Ruby on rails 未初始化的常量LineItemsController::CurrentCart rails 4.2迭代D3
Ruby on rails 未初始化的常量LineItemsController::CurrentCart rails 4.2迭代D3,ruby-on-rails,Ruby On Rails,我正在学习rails 4的敏捷web开发这本书。 我目前在迭代D3,我得到了一个路由错误的股票。 “未初始化的常量LineItemsController::CurrentCart” 请帮忙。谢谢你 完整代码->Github class LineItemsControllerproduct) 回应待办事项|格式| 如果@line\u item.save format.html{redirect_to(@line_item.cart,:notice=>“行项目已成功创建”)} format.xml
我正在学习rails 4的敏捷web开发这本书。 我目前在迭代D3,我得到了一个路由错误的股票。
“未初始化的常量LineItemsController::CurrentCart”
请帮忙。谢谢你
完整代码->Github
class LineItemsControllerproduct)
回应待办事项|格式|
如果@line\u item.save
format.html{redirect_to(@line_item.cart,:notice=>“行项目已成功创建”)}
format.xml{render:xml=>@line\u item,:status=>:created,:location=>@line\u item}
其他的
format.html{render:action=>“new”}
format.xml{render:xml=>@line_item.errors,:status=>:unprocessable_entity}
结束
结束
结束
看起来您还没有创建CurrentCart类,请仔细检查这本书,它应该在某个部分中创建。我已经修复了它
重命名文件
文件名应该是
current\u cart.rb
而不是current\u cat.rb
太好了!这就是解决办法。
class LineItemsController < ApplicationController
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