Which is the best way to create a thin key/value related to some model? where a field only could insert those values (keys as 0,1) and where could be showed the values (as Red, Blue) from a drop-list COLOUR_OPTIONS = {0=>"Red", 1=>"Blue"} t.string :colour --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 6, 2007 2:40 PM, Kless <jonas.esp-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > Which is the best way to create a thin key/value related to some > model? where a field only could insert those values (keys as 0,1) and > where could be showed the values (as Red, Blue) from a drop-list > > COLOUR_OPTIONS = {0=>"Red", 1=>"Blue"} > > t.string :colour > >validates_inclusion_of :colour, :in => COLOUR_OPTIONS.keys That might give you some ideas for starters. I will say that I would prefer to just store the actual values ("Red", "Blue", etc.) or if you want to store numeric keys, then create an actual table and setup an association. class Whatever < ActiveRecord::Base belongs_to :colour end class Colour < ActiveRecord::Base has_many :whatevers end HTH, Michael Guterl --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks. I''ll use tables. On 7 nov, 00:41, "Michael Guterl" <mgut...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Nov 6, 2007 2:40 PM, Kless <jonas....-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > Which is the best way to create a thin key/value related to some > > model? where a field only could insert those values (keys as 0,1) and > > where could be showed the values (as Red, Blue) from a drop-list > > > COLOUR_OPTIONS = {0=>"Red", 1=>"Blue"} > > > t.string :colour > > validates_inclusion_of :colour, :in => COLOUR_OPTIONS.keys > > That might give you some ideas for starters. > > I will say that I would prefer to just store the actual values ("Red", > "Blue", etc.) or if you want to store numeric keys, then create an actual > table and setup an association. > > class Whatever < ActiveRecord::Base > belongs_to :colour > end > > class Colour < ActiveRecord::Base > has_many :whatevers > end > > HTH, > Michael Guterl--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---