title: Building a shopping cart with rails
body: <p>New to rails. I have seen several tutorials online, but am unable to get a simple shopping cart functionality. Following is my code and the error i am getting.</p>
  
  <pre><code>class CartsController &lt; ApplicationController
  
  def add
      @current_cart = @cart
      @current_cart = @current_cart.products.new(product_params)
      @current_cart.save
      session[:current_cart_id] = @current_cart.id
  
      redirect_to :back
    end
  
  
  
  def delete
    end
  
    def show
      #@cart = initialize_cart.cart
    end
  
    private
  
    def product_params
      params.permit(:id)
    end
  
  end
  </code></pre>
  
  <p>Application Controller</p>
  
  <pre><code>class ApplicationController &lt; ActionController::Base
    protect_from_forgery with: :exception
  
    before_filter :initialize_cart
  
    def initialize_cart
      if session[:cart]
        @cart = Cart.find(session[:cart])
      else
        @cart = Cart.create
        session[:cart] = @cart.id
      end
    end
  
  end
  </code></pre>
  
  <p>Link to Add to Cart Button</p>
  
  <pre><code>&lt;%= link_to "Add to Cart", :controller =&gt; "carts", :action =&gt; "add", :id =&gt; @product.id, :class =&gt; "btn bg-turquoise"%&gt;
  </code></pre>
  
  <p>routes.rb</p>
  
  <pre><code>get 'carts/add/:id', to: 'carts#add'
  
  get 'carts/delete'
  
  get 'carts/show', to: 'carts#show', as: 'showcart'
  </code></pre>
  
  <p>Error:</p>
  
  <p>ActiveModel::UnknownAttributeError in CartsController#add</p>
  
  <p>unknown attribute 'cart_id' for Product.</p>
  
  <p>Extracted source (around line #5):</p>
  
  <pre><code>3 def add
  4   @current_cart = @cart
  **5     @current_cart = @current_cart.products.new(product_params)**
  6   @current_cart.save
  7   session[:current_cart_id] = @current_cart.id
  </code></pre>
  
  <p>Any help or guidance is appreciated. Thanks!</p>