[英]Why am I getting this strange routing error?
Why am I getting this strange routing error when I click the "Create Questions" button? 当我单击“创建问题”按钮时,为什么会收到此奇怪的路由错误?
No route matches [POST] "/questions"
I have... 我有...
/config/routes.rb : /config/routes.rb :
resources :questions, :only => [:index, :update, :destroy, :edit]
resources :products do
resources :questions, :except => [:index, :update, :destroy, :edit]
end
/app/controllers/questions_controller.rb : /app/controllers/questions_controller.rb :
def new
@product = Product.find(params[:product_id])
session[:product] = @product.id
@question = @product.questions.build
end
def create
@product = Product.find(session[:product])
flash[:notice] = "Question was successfully created." if @question = @product.questions.create(params[:question])
respond_with @product, @question
end
/app/views/questions/_form.html.haml : /app/views/questions/_form.html.haml :
= simple_form_for @question do |f|
= f.association :products, :label => "Products" unless @product.present?
= f.button :submit, :id => 'submit_question'
I always access questions#new
from products#show
, so @product.present?
我总是从products#show
@product.present?
访问questions#new
,所以@product.present?
is always true. 永远是真的。
您在路线中缺少:create动作:
resources :questions, :only => [:index, :update, :destroy, :edit, :create]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.