Populating associations


#1

Hi all,

I have a Message class which has_many Message_Users, Message_User is
basically a join table with an attribute, and belongs_to a User.

so it kinda looks like the following:

Message has_many :message_users

MessageUser belong_to :user

User - lots of user stuff

What I want to do, is on the Message create screen have a list box with
all the users in it, and when the Message is created have it
automagically
create 1 MessageUser for each user selected, and link them to the new
Message through the MessageUser association. Is this possible, or do I
need to grab the list of users selected and manually create the
structures?
Or can anyone see a better way to set up the structures?

Hope the question is clear.
Cheers
Simon


#2

You may want to check out this blog post. I think it may help with
what you are looking to do:

http://www.justinball.com/2008/07/03/checkbox-list-in-ruby-on-rails-using-habtm/