Hi, I''m trying to define multiple choices inside the rails model. In Django I would do something like this: location = models.CharField( max_length=3, choices=LOCATION_CHOICES, help_text="Which location do you prefer?" ) LOCATION_CHOICES = ( (''AMS'', ''Amsterdam''), (''RTM'', ''Rotterdam''), (''HAG'', ''The Hague''), ) What is the Rails equivalent of the above code? I''ve tried searching the Rails docs and Googling, but with no luck. Thanks! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I don''t know Django, but it looks to me like you are trying to setup a hash. location_choices can be a local variable, instance variable, constant, etc depending on your needs. @location_choices = { "AMS" => "Amsterdam", "RTM" => "Rotterdam" } If you want it to be a constant, just capitalize it. Local variable, no @ sign. Andrew -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Reasonably Related Threads
- Patch to improve malformed vorbiscomment handling
- Patch to improve malformed vorbiscomment handling
- ACLs: Group ACL adds empty ACL for user of same name, why?
- [PATCH] lib: Use a common function to validate strings.
- Re: [PATCH] lib: Use a common function to validate strings.