How to use has_many :through association??

16 views
Skip to first unread message

David Maxwell

unread,
Oct 9, 2014, 7:14:44 PM10/9/14
to rubyonra...@googlegroups.com
Let's say I have

group
has_many :memberships
has_many :members, :through => memberships

and vice versa, and there's a model called memberships that stores extra
information, such as the reason for joining, etc.

How do I then actually USE this in my models, controllers and views?

Do I need to create new memberships using a form?

Can I for instance, on a group's show view that displays an individual
group, have a form at the bottom that allows the CURRENT USER to JOIN
the group and provide a reason for joining by sending a put request form
to the memberships controller?
How would I access the memberships form if I'm on the group's page?

Thank you for your help and patience.

--
Posted via http://www.ruby-forum.com/.

Sai Ch

unread,
Oct 10, 2014, 1:29:11 AM10/10/14
to rubyonra...@googlegroups.com
I can't get what you exactly need but I am prefered to refer this link

http://blog.teamtreehouse.com/what-is-a-has_many-through-association-in-ruby-on-rails-treehouse-quick-tip
Reply all
Reply to author
Forward
0 new messages