我在我的 rails 应用程序中添加了一条额外的路由到我的嵌套资源中,就像这样。
resources :questions do
resources :answers do
match "/bestanswer", :to => "answers#bestanswer", :via => :post
end
end
运行 'rake routes' 显示以下路径
question_answer_bestanswer POST /questions/:question_id/answers/:answer_id/bestanswer(.:format) answers#bestanswer
我尝试以这样的形式使用路径(每个答案重复多次)
<%= form_tag question_answer_bestanswer_path, method: :post do%>
<%= hidden_field_tag :answer_id, answer.id %>
<%= hidden_field_tag :question_id, answer.question.id %>
<%= submit_tag "Accept this answer as the best answer", :class => 'btn ' %>
<% end %>
但是,当我转到显示此表单的页面时,我收到此错误
No route matches {:controller=>"answers", :action=>"bestanswer"}
你能解释一下我做错了什么吗?