title: How to insert rows in a many-to-many relationship
body: <p>I am having an issue trying to save into an intermediate table. I am new on Rails and I have spent a couple of hours on this but can't make it work, maybe I am doing wrong the whole thing. Any help will be appreciated. =)</p>
  
  <p>The app is a simple book store, where a logged-in user picks books and then create an order.</p>
  
  <p>This error is displayed:</p>
  
  <pre><code>NameError in OrderController#create
  uninitialized constant Order::Orderlist
  </code></pre>
  
  <p><br />
  These are my models:</p>
  
  <pre><code>class Book &lt; ActiveRecord::Base  
      has_many :orderlists
      has_many :orders, :through =&gt; :orderlists
  end
  
  class Order &lt; ActiveRecord::Base
      belongs_to :user
      has_many :orderlists
      has_many :books, :through =&gt; :orderlists
  end
  
  class OrderList &lt; ActiveRecord::Base
      belongs_to :book
      belongs_to :order
  end
  </code></pre>
  
  <p><br />
  This is my Order controller:</p>
  
  <pre><code>class OrderController &lt; ApplicationController
  
      def add
          if session[:user]
              book = Book.find(:first, :conditions =&gt; ["id = #{params[:id]}"])
              if book
                  session[:list].push(book)
              end
              redirect_to :controller =&gt; "book"
          else
              redirect_to :controller =&gt; "user"
          end
       end
  
      def create
          if session[:user]
              @order = Order.new
              if @order.save
                  session[:list].each do |b|
                      @order.orderlists.create(:book =&gt; b) # &lt;-- here is my prob I cant make it work
                  end
              end
          end
          redirect_to :controller =&gt; "book"
      end
  end
  </code></pre>
  
  <p>Thnx in advance!<br>
  Manuel</p>