I’m thinking about a social networking-site. My user-model should have an attribute ‘eyecolor’, which could be set on a view-page with a select-box/dropdownlist.
My question: -> should I make a AR-Model or should I use a global Hash/Constant for the data? Is there a best practice for ‘static-models’?
And how do I associate following without an AR-Model with relations:
u = User.first u.eyecolor ==> 1 (not the eyecolor-string!)
What I need is the eyecolor-string:
u = User.first u.eyecolor ==> 'brown'
Thanks, sorry for my bad english!
You could create a model to handle your eye-color logic:
Note: this model is not an Active Record model, but it does create an abstraction the real-world object you are trying to model.
EDIT: I also like this approach as opposed to a global hash, because it gives it organizes your static definition within EyeColor instead of floating around in your program, which makes it clear where this definition is.
EDIT: added question mark to predicate method.