Don't know what the best practice is, but the way I do it is in the model
class User < ActiveRecord::Base
UserGenders = {:male => 1, :female => 2}
end
Then from code I just do if user.gender_id == User::UserGenders[:male]
On Mon, Jun 11, 2012 at 1:45 PM, Matt Martini <[email protected]>wrote:
> Hello,
>
> What is the best way to to do enumerations of values that you want to use
> to provide values for a field. There are many cases where you want the
> user to choose from a list of values, but you really don't need a whole
> model to support. Yet, it should be flexible enough to able to be changed.
>
> A simple example would be a gender field in a person record. There needs
> to be somewhere to store the 'male' and 'female' values to be used in a
> select field,
> but we don't want to hard code these values because later we might add
> 'unknown' as an option, or change to 'boy' and 'girl'. With only two
> values it seems pointless to have a whole model dedicated to this, yet it
> still needs to be somewhat dynamic as the values could change.
>
> What is the best practice for this type of data?
>
> Matt
>
>
> --
> 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
~ Jeremiah:9:23-24
Android 2D MMORPG: http://solrpg.com/,
http://www.youtube.com/user/revoltingx
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.