title: rails- creating record in a join table
body: <p>I'm trying to create a record within a join table from the action of a button. To explain, I would have an events model and would like to track selected events from each user.</p>
  
  <p>I used the HABTM relationship since I dont really need any extra fields.</p>
  
  <p>User.rb => has_to_and_belongs_to_many :events 
  Event.rb => has_to_and_belongs_to_many :users
  Events_Users Migration => [user_id, event_id, id=>false]</p>
  
  <p>So how I thought I would do it is.... </p>
  
  <p>users_controller.rb =></p>
  
  <pre><code>def add_event
  @user = User.find(session[:user_id])
  params[:user][:event_ids] ||= []
    if @user.update_attributes(params[:user])
        flash[:notice]='Added to My Events'
    redirect_to :action =&gt; "index"
        end  
   end
  </code></pre>
  
  <p>and the btn_link looks like....</p>
  
  <pre><code>&lt;% @events.each do |event| %&gt;
  &lt;%= link_to image_tag("heart.gif"), :controller =&gt; 'user', :action =&gt; 'add_event' %&gt;
  &lt;%=h event.name %&gt;
  &lt;%=h event.description %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>But I'm not sure how to check to see if its working...How would I perform these action in the console so I can check if the records being added?</p>
  
  <pre><code>u = User.find(1)
  e = Event.find(1)
  </code></pre>
  
  <p>????? x = u.e.create  ?????</p>