Rails model to represent multiple fields
Posted
by Tristan O'Neil
on Stack Overflow
See other posts from Stack Overflow
or by Tristan O'Neil
Published on 2010-06-08T14:20:27Z
Indexed on
2010/06/08
14:42 UTC
Read the original article
Hit count: 182
ruby-on-rails
|ruby
I'm developing a rails project where I have one data model with multiple fields that are collection selects. I'd like to create another model to represent all of these collection select fields. So, for instance, my main data model has three collection select fields -- one for county, one for category, and one for classification. I could separate these into three separate data models, but that seems redundant since they all share the same characteristics. They have a type and a value, like a county is a county and it has a value of let's say Sonoma, just as category has a type of category and a value of let's say Winery. If you've ever used Drupal, I'm basically looking for the behavior of the taxonomy functionality.
So you see my dilemma: I need to separate these fields into three separate fields but they have very similar data structures. Any suggestions would be greatly appreciated.
© Stack Overflow or respective owner