On 25 January 2011 06:39, Niklas Nson
<niklasnson-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org>
wrote:> I would need some help on pointing me to the correct direction. In
> application i would like users to be abel to select genres for work
> they like to do. A user can be willing to do a lot of genres or just
> one. If i still was writing code in .NET i would do a string of
id''s
> and then save them to the database.
>
> How would one do this in Ruby On Rails, are something like =>
>
> Class User
> has_one :profile
> end
>
> Class Profile
> belongs_to :user
> has_many :genres
> end
>
> Class Genre
> has_many :profiles
> end
>
> And then genre would have profile_id and genre_id (so i can get a
> translated text for that id).
If a profile can have many genres and a genre can have many profiles
then you need a has_and_belongs_to_many association. Have a look at
the Rails Guide on ActiveRecord Relationships for more information.
Colin
>
> What would you do ?
>
> --
> 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@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
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@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.