KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I know there is no real equivalent in Rails but my question is mostly about best practice... In Django, if you want to limit a model field to a limited set of choices, you would do something like this (in your model): COLOR_CHOICES = (('B', 'Blue'), ('R', 'Red')) item_color = models.CharField(choices=COLOR_CHOICES) From my (basic) understanding of Rails, I can achieve something similar, for example, by using a select tag in the forms dealing with adding/editing that model... My question however is, where would it be appropriate to declare the "choices" hash (again I'm guessing here that a hash is what I need?). Basically I just want it to be easily re-usable in any forms where I might need to present those choices, and when it comes to validating at the model level. Any help/tips would be appreciated!
Tags (comma-separated)
Save Edits
Cancel