1

[質問の作成] ボタンをクリックすると、この奇妙なルーティング エラーが発生するのはなぜですか?

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 です。

4

1 に答える 1

2

ルートに :create アクションがありません:

resources :questions, :only => [:index, :update, :destroy, :edit, :create]
于 2013-04-30T11:38:11.377 に答える