我知道在嵌套资源中,您必须传递包含资源的id才能使其工作。Rails-如何在包含资源时路由到嵌套资源未设置
但是,我想允许用户为产品创建一个评论,并在新视图中指定表单中的产品,而不是实际将其传入到路径中。因此,不要在产品上进行审核,而应该有一个主审查表格,您可以在表格中选择任何产品。
我收到一个错误,试图做到这一点,无法弄清楚 - 什么是解决方案?
#error
No route matches {:action=>"new", :controller=>"reviews"}
#view
new_product_review_path
#controller
def new
#@product = Product.new
@review = Review.new
end
#routes.rb
resources :products do
resources :reviews
end
顺便说一句,为什么你的行为中有@product = Product.new? – 2013-05-07 05:32:39