Ruby on rails 未定义的方法'order#u path';对于#<#&书信电报;类别:0x0000102EFF18>;:0x00000100f3c9c8>;
这是我的控制器文件:Ruby on rails 未定义的方法'order#u path';对于#<#&书信电报;类别:0x0000102EFF18>;:0x00000100f3c9c8>;,ruby-on-rails,ruby,ruby-on-rails-3.2,Ruby On Rails,Ruby,Ruby On Rails 3.2,这是我的控制器文件: class OrdersController < ApplicationController ... def create @order = current_user.current_cart.order #get a current order if @order.nil? @order = current_user.current_cart.build_order #if one does not exist, c
class OrdersController < ApplicationController
...
def create
@order = current_user.current_cart.order #get a current order
if @order.nil?
@order = current_user.current_cart.build_order #if one does not exist, create it
end
@order.update_attributes!(...) #update the attributes
render :new
end
...
end
无论何时,@order=order.new
它都能工作,如果我这样做,它就会工作。但是,当我在呈现模板之前保存或更新某个内容时,就会出现错误。我想保存模型
在路由中,顺序是一个简单的资源:顺序。我也有同样的错误。当路由.rb
resources :orders, only: [:index, :create, :edit] do
# ...
end
解决方案
添加:更新
resources :orders, only: [:index, :create, :edit, :update] do
# ...
end
这个错误应该是一个线索。它缺少order_路径,这并不奇怪,因为您正在路由文件中为多个订单定义路由?那么,确保resources:order进入:orders控制器的最佳方式是什么?或者我可以在资源中加入一些东西:修复这个问题的命令。再次感谢。好的,参考资料:订单确实解决了这个问题,但我必须对表单进行其他处理以使其完美工作。谢谢你的提示,马克!
resources :orders, only: [:index, :create, :edit, :update] do
# ...
end