def remove_items
line_items.each do |item|
@ci = Product.find(item.id)
@ci.quantity = @ci.quantity.to_i - 1
end
您好,我正在嘗試使用該項目的id,然後將該id與產品匹配,然後減去該產品的quantity屬性的1。ruby on rails查詢
我目前得到這個錯誤。
TypeError in OrdersController#create
can't convert nil into String
出了什麼問題? 謝謝
OrderController#create 請記住,由於正在進行,代碼很sc code。 :)
def create
@order = current_cart.build_order(params[:order])
@order.ip_address = request.remote_ip
@cart = current_cart
if @order.save
if @order.purchase
@order.status = "paid"
@cart.remove_items
@cart.destroy
render :action => "success"
else
@order.status = "failed"
@cart.destroy
render :action => "failure"
end
else
render action: "new"
end
末
我覺得這是堆棧跟蹤
[0m
←[1m←[35mLineItem Load (0.0ms)←[0m SELECT "line_items".* FROM "line_items" WH
ERE "line_items"."cart_id" = 129
←[1m←[36mProduct Load (0.0ms)←[0m ←[1mSELECT "products".* FROM "products" WHE
RE "products"."id" = ? LIMIT 1←[0m [["id", 147]]
Completed 500 Internal Server Error in 5762ms
TypeError (can't convert nil into String):
app/controllers/application_controller.rb:60:in `+'
app/controllers/application_controller.rb:60:in `record_not_found'
在控制器和堆棧跟蹤中發佈完整操作。 – fotanus
向我們展示'OrdersController'上'create'的作用和'rake routes'的輸出 –
Added OrderController。現在將獲得耙路線 – baihu