未定义的局部变量或方法`cart_id'

时间:2013-02-10 03:40:16

标签: ruby-on-rails cart

我有一些问题,我在任务D:购物车创建,Iam创建问题时,使用书籍Agile web开发和rails。

背景信息。
控制器/ application_controller.rb

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

控制器/ line_items_controller.rb

def create


@cart = current_cart
product = Product.find(params[:product_id])
@line_item = @cart.line_items.build(:product_id => product.id )
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
end

0 个答案:

没有答案