在routes.rb中我有:
resources :dtests do
resources :dquestions
end
“/ dtests / 2 / dquestions / 3”类型的所有活动和路线都正常工作,但当我尝试输入“dtests / 2 / dquestions”时,出现错误:
No route matches {:action=>"show", :controller=>"dquestions", :locale=>:en, :dtest_id=>#<Dquestion id: 1, question_text: "dfs", count_answer: 4, dtest_id: "1", created_at: "2013-06-01 09:32:41", updated_at: "2013-06-01 09:32:41">}
在服务器日志中:
Dquestion Load (0.5ms) SELECT "dquestions".* FROM "dquestions" WHERE "dquestions"."dtest_id" = 1
default_url_options is passed options: {}
Rendered dquestions/index.html.erb within layouts/application (39.5ms)
Completed 500 Internal Server Error in 106ms
ActionController::RoutingError
请告诉我,问题是什么?
答案 0 :(得分:0)
看这里:
:dtest_id=>#<Dquestion id: 1, question_text: "dfs", count_answer: 4, dtest_id: "1", created_at: "2013-06-01 09:32:41", updated_at: "2013-06-01 09:32:41">
不知何故,你传递整个对象而不是id。无法说明为什么to_param
不会自动触发。
无论如何,只需在网址助手中将.id
添加到您的对象中。