title: Ruby on Rails 3: HABTM with new controller action
body: <p>I'm trying to create a M:N relationship for a project-model that has_and_belongs_to _many users. A user can join many projects but projects also have many users. I guess I don't need a through cause my join table won't have another column. </p>
  
  <p>So I included the association in my two models (has_and_belongs_to_many :projects
  and  has_and_belongs_to_many :users) and set up a new migration:</p>
  
  <pre><code>class AddProjectsUsersTable &lt; ActiveRecord::Migration
    def self.up
      create_table :projects_users, :id =&gt; false do |t|
        t.references :project, :user
      end
    end
  
    def self.down
      drop_table :projects_users
    end
  end
  </code></pre>
  
  <p>That's working..
  I'm not sure whether the next things are right or not - but I tried something.
  I tried to create a new action in my user controller where I can set a relationship to this user to a project. </p>
  
  <pre><code>  def joinProject
      @user = current_user
      @user.projects = Project.find(params[:id])
  
      respond_to do |format|
          format.html { redirect_to @project, notice: 'Successfully joined project.' }
          format.json { head :no_content }
      end
    end
  </code></pre>
  
  <p>It is probably the wrong way cause it says: "<code>undefined method 'each' for #&lt;Project:0x00000103f10028&gt;</code>" </p>
  
  <p><strong>How can I else set this relationship?
  Seems like I didn't really understand how this HABTM relationship is working..</strong></p>
  
  <p>Can please anybody help me?</p>
  
  <p>Some further information that may be interesting or wrong ;)</p>
  
  <p>I created this route:</p>
  
  <pre><code>  match "joinProject_user/:id" =&gt; "users#joinProject", :as =&gt; :joinProject
  </code></pre>
  
  <p>And I called the controller action in my view as follows: </p>
  
  <pre><code> &lt;%= link_to 'Join', joinProject_path(project) %&gt;
  </code></pre>