为什么当我单击“创建问题”按钮时会出现这个奇怪的路由错误?
No route matches [POST] "/questions"
我有...
/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:
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:
= simple_form_for @question do |f|
= f.association :products, :label => "Products" unless @product.present?
= f.button :submit, :id => 'submit_question'
我总是questions#new
从访问products#show
,所以@product.present?
总是如此。