我正在尝试获取给定参数的网址:
url_for({
:action => "show",
:controller => "questions",
:dashboard_id => "123",
:dashboard_type => "mono",
:question_id => "1234",
:only_path => true
})
但是我收到了这个错误:
ActionController::RoutingError: No route matches {:action=>"show", :controller=>"questions", :dashboard_id=>"123", :dashboard_type=>"mono", :question_id=>"1234"}
在我的routes.rb
文件中,我有这样的配置:
resources :dashboards, :only => [:index, :all, :create] do
resources :questions, :path => '/:dashboard_type/questions'
end
什么似乎是问题?
答案 0 :(得分:2)
将:question_id
替换为:id
应该是
url_for({
:action => "show",
:controller => "questions",
:dashboard_id => "123",
:dashboard_type => "mono",
:id => "1234",
:only_path => true
})
由于没有:question_id
dashboard_question GET /dashboards/:dashboard_id/:dashboard_type/questions/:id(.:format) questions#show