Search code examples
ruby-on-railsmodel-associations

How to store possible attributes in rails


I have Question model , which has attributes "status" , "code" , "type" .

All three attributes should be a drop down , say status can be "active / closed/ inactive" and so on.

All possible options for these drop-down's should be from database. What is the best way to store this.

I planned to create new model say lookup which has

[lookup_for][lookup_type][lookup_value] 

and link that model to questions with HABTM and create a joint table lookup_questions.

So that I can get all status to fill dropdown by querying lookup table like

@questions_status = lookup.find_by_lookup_type('status')

I am in right direction ?, i am not rails experienced, please advice me.


Solution

  • Finally I followed HABTM relationship. I think that is the more right way for my app (since the lookups will keep on updating).