17 Nov 2012, 17:40
Generic-user-small

Liu Xiong (3 posts)

Hello, Errors: NameError in LineItemsController#create

uninitialized constant ActiveRecord::RecordNotFind

app/controllers/application_controller.rb:8:in rescue in current_cart' app/controllers/application_controller.rb:7:in current_cart’ app/controllers/line_items_controller.rb:43:in `create’

What I have in application_controller is

class ApplicationController < ActionController::Base protect_from_forgery

private
def current_cart
    Cart.find(session[:cart_id])
rescue ActiveRecord::RecordNotFound
    cart = Cart.create
    session[:cart_id] = cart.id
    cart
end
end

and in line_items_controller :

def create
  @cart = current_cart
  product = Product.find(params[:product_id])
  @line_item = @cart.line_items.build(:product => product)
  #@line_item = LineItem.new(params[:line_item])
end
respond_to do |format|
  if @line_item.save
    format.html { redirect_to(@line_item.cart, :notice => 'Line item was successfully created.') }
    format.json { render :json => @line_item, :status => :created, :location => @line_item }
  else
    format.html { render :action => "new" }
    format.json { render :json => @line_item.errors, :status => :unprocessable_entity }
  end
end

I don’t kown why?

17 Nov 2012, 17:45
Generic-user-small

Liu Xiong (3 posts)

and I don’t know why the generate url is http://0.0.0.0:3000/line_items?product_id=1

I guess my current_cart is wrong,but i can’t find it.

I need your help!

Thank you!

20 Nov 2012, 07:49
Generic-user-small

Liu Xiong (3 posts)

Problem has been soveled.

  You must be logged in to comment