0

在 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 

请告诉我,有什么问题?

4

1 回答 1

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在 url 帮助程序中添加到您的对象。

于 2013-06-07T07:50:37.980 回答