[質問の作成] ボタンをクリックすると、この奇妙なルーティング エラーが発生するのはなぜですか?
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?
常に true です。