title: Rails - Connecting checkboxes to change values for a join table
body: <p>I have two models Events and Interests which are connected by a join table migration EventsInterests (event_id, interest_id, id=>false).</p>
  
  <p>I was trying to create something where you could connect a set of interest categories to some events within my app.</p>
  
  <p>I created a record in directly in the database and its showing up correctly, so I'm pretty sure the checkbox part is correct; but I cant edit the the record at all.  If I add another interest through the checkbox, nothing happens..Im not getting any errors and the log shows it calling the join table, so I'm guessing the issue is with my update statement.....</p>
  
  <p>Im thinking its something with attr_accessible part but I dont know how to add that for a join table....do i just delete it?</p>
  
  <p>events.rb </p>
  
  <pre><code>  has_and_belongs_to_many :interests
    attr_accessible :name, :category
  </code></pre>
  
  <p>interests.rb</p>
  
  <pre><code>  has_and_belongs_to_many :events
  </code></pre>
  
  <p>In my edit form where I would like to add the records to the join table it looks like this.</p>
  
  <pre><code>&lt;%= form_for @event do |f| %&gt;
  &lt;%= f.error_messages %&gt;
  
  &lt;p&gt;
     &lt;%= f.label :title %&gt;&lt;br /&gt;
      &lt;%= f.text_field :title %&gt;
   &lt;/p&gt;
  
   &lt;% for interest in @interests %&gt;
  &lt;div&gt;
  &lt;%= check_box_tag "event[interest_ids][]", interest.id, @event.interests.include?(interest) %&gt;
  &lt;%= interest.name %&gt;
  &lt;/div&gt;
  &lt;% end %&gt;   
     &lt;p&gt;&lt;%= f.submit %&gt;&lt;/p&gt;
  </code></pre>
  
  <p>and the edit/update part in the controller looks like</p>
  
  <pre><code> def update
  @event = Event.find(params[:id])
  params[:event][:interest_ids] ||= []
  if @event.update_attributes(params[:event])
    flash[:notice] = "Successfully updated event."
    redirect_to @event
  else
    render :action =&gt; 'edit'
  end
    end
  </code></pre>