small medium large xlarge

Generic-user-small
24 Jul 2011, 19:55
Oleg (1 post)

I get: NoMethodError in LineItemsController#create undefined method line_items' for 6:Fixnum app/controllers/line_items_controller.rb:53:in create’

def create @cart = current_cart product = Product.find(params[:product_id]) @line_item = @cart.line_items.build(:product => product)

respond_to do |format|
  if @line_item.save
    format.html { redirect_to(@line_item.cart,
      :notice => 'Line item was successfully created.') }
    format.xml  { render :xml => @line_item,
      :status => :created, :location => @line_item }
  else
    format.html { render :action => "new" }
    format.xml  { render :xml => @line_item.errors,
      :status => :unprocessable_entity }
  end
end   end

Not sure where I’ve gone wrong. Any ideas?

Elefante_pragsmall
10 Oct 2011, 18:36
Fernando Campos (4 posts)

I am on ruby 1.9.2 and Rails 3.1

Try this line without a rash rocket (=>)

@line_item = @cart.line_items.build(:product => product)

should be:

@line_item = @cart.line_items.build(product: product)

If it’s not the case, make sure the method current_cart() in application.rb is returning cart.

Best regards

You must be logged in to comment