title: Ruby on Rails 3: Session issue: Loosing content
body: <p>i have an error but i can't pinpoint the source :(  it works fine the first time i use the add_to_cart action, but the second time i have this error raising.</p>
  
  <pre><code>Started GET "/home/add_to_cart?id=5&amp;money=USD" for 10.0.1.3 at 2013-05-26 17:22:42 +0200
   Processing by HomeController#add_to_cart as HTML
   Parameters: {"id"=&gt;"5", "money"=&gt;"USD"}
   Completed 500 Internal Server Error in 2ms
  
  NoMethodError (undefined method `+' for nil:NilClass):
    app/models/cart.rb:14:in `add_artwork'
    app/controllers/home_controller.rb:39:in `add_to_cart'
  </code></pre>
  
  <p>it seems the object @cart is lost or something.... or the object 'artwork' is lost... i don't know...</p>
  
  <p>the controller</p>
  
  <pre><code>def add_to_cart
    artwork = Artwork.find(params[:id])
    @cart = find_or_create_cart
    @cart.add_artwork(artwork)   #--- line 39
    redirect_to(:action =&gt; 'show_cart')
  end
  
  def show_cart
    @cart = find_or_create_cart
  end
  
  private
  
  def find_or_create_cart
    session[:cart] ||= Cart.new
  end  
  </code></pre>
  
  <p>cart.rb</p>
  
  <pre><code>class Cart
  
    attr_reader :items
    attr_reader :total_price
  
    def initialize
       @items = []
       @total_price = 0.0
    end
  
    def add_artwork( artwork )
      @items &lt;&lt; LineItem.new_based_on(artwork)
      @total_price += artwork.price   #---- line 14
    end
  end
  </code></pre>
  
  <p>line_item.rb</p>
  
  <pre><code>class LineItem &lt; ActiveRecord::Base
  
    belongs_to :artwork
    belongs_to :order
  
    def self.new_based_on ( artwork  )
      line_item = self.new
      line_item.artwork = artwork
      line_item.price = artwork.price
      return line_item
    end
  end
  </code></pre>
  
  <p>session_store.rb</p>
  
  <pre><code>  Larrabyblaine::Application.config.session_store :active_record_store
  </code></pre>