# Populating associations

**URL:** <https://www.ruby-forum.com/t/populating-associations/156229>\
**Category:** Rails\
**Created:** [December 23, 2008, 3:00am UTC](https://www.ruby-forum.com/t/populating-associations/156229 "2008-12-23T03:00:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijomo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/87869e/32.png) [@sijomo](https://www.ruby-forum.com/u/sijomo)\
**Post date:** [December 23, 2008, 3:00am UTC](https://www.ruby-forum.com/t/populating-associations/156229/1 "2008-12-23T03:00:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sijomo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/87869e/32.png) [@sijomo](https://www.ruby-forum.com/u/sijomo)\
**Post date:** [December 23, 2008, 10:40pm UTC](https://www.ruby-forum.com/t/populating-associations/156229/2 "2008-12-23T22:40:45Z")

</div>

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/](http://www.justinball.com/2008/07/03/checkbox-list-in-ruby-on-rails-using-habtm/)
