# Updating join table (HMT) with checkbox and extra fields

**URL:** <https://www.ruby-forum.com/t/updating-join-table-hmt-with-checkbox-and-extra-fields/167701>\
**Category:** Rails\
**Created:** [May 11, 2009, 6:44pm UTC](https://www.ruby-forum.com/t/updating-join-table-hmt-with-checkbox-and-extra-fields/167701 "2009-05-11T18:44:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 11, 2009, 6:44pm UTC](https://www.ruby-forum.com/t/updating-join-table-hmt-with-checkbox-and-extra-fields/167701/1 "2009-05-11T18:44:08Z")

</div>

Hi,  
I’ve been breaking my head over this thing with no success. Here is my  
table layout -

class User \< AR  
has\_many :memberships  
has\_many :groups, :through =\> :memberships  
…

class Group \< AR  
has\_many :memberships  
has\_many :users, :through =\> :memberships  
…

class Membership \< AR  
belongs\_to :user, :class\_name =\> “User”, :foreign\_key =\> “user\_id”  
belongs\_to :group, :class\_name =\> “Group”, :foreign\_key =\>  
“Group\_id”  
…

Now, Membership table has an extra field called membership\_id and I  
want the user to fill in that id in the edit form.

My view looks like this. The checkbox fields works great and I can  
update my db pretty well (barring minor issues).

\<% form\_for :user, @user, :url =\> { :action =\> ‘save\_memberships’} do |  
form| %\>  
\<%= form.error\_messages %\>  
\<% @groups.each do |g| %\>  
\<%= check\_box\_tag(“user[membership\_ids][]”, g.id,  
@user.groups.include?(g)) %\>  
\<%= “#{g.name}”%\>  
  
----\> I have to invoke my partial to collect membership id here. But  
can’t get the call right. The partial is below.  
\<% end%\>  
\<% end%\>

This is the membership partial -

 \<% fields\_for "user[membership\_ids][]", membership do |f| %\> Membership id: \<%= f.text\_field :membership\_id %\> \<% end %\>

Any ideas how I can do this?

thanks
