【发布时间】:2012-01-27 17:24:11
【问题描述】:
我们正在将 Rails 2.3 应用程序转换为 3.0.11,但在迁移某些路由时遇到了问题。
在我看来,我们的自定义参数(:title 和 :name_recognition)似乎导致了一些问题。但是,我们使用的是命名路由,所以我非常不清楚 Rails 为什么要尝试通过控制器、操作和参数进行任何匹配。
我们得到的错误:
ActionView::Template::Error (No route matches {:controller=>"audience_tool", :action=>"show", :name_recognition=>"BandName", :title=>"", :id=>1388}):
这是来自 routes.rb 的有问题的路线:
match ':name_recognition/:title/:id' => 'audience_tool#show', :as => :show_page
这是“rake routes”的结果:
show_page /:name_recognition/:title/:id {controller=>"audience_tool", :action=>"show"}
这是我们用来构建 URL 的模型方法:
def url(options=Hash.new)
options.reverse_merge!({
:name_recognition => name_recognition,
:title => title,
:id => id
})
show_page_path options
end
这是我们如何调用方法:
link_to("The Link text", show.url)
堆栈跟踪,减去错误中显示的模板代码:
actionpack (3.0.11) lib/action_dispatch/routing/route_set.rb:425:in `raise_routing_error'
actionpack (3.0.11) lib/action_dispatch/routing/route_set.rb:398:in `generate'
actionpack (3.0.11) lib/action_dispatch/routing/route_set.rb:454:in `generate'
actionpack (3.0.11) lib/action_dispatch/routing/route_set.rb:482:in `url_for'
actionpack (3.0.11) lib/action_dispatch/routing/url_for.rb:131:in `url_for'
actionpack (3.0.11) lib/action_dispatch/routing/route_set.rb:195:in `show_page_path'
app/models/performance.rb:245:in `url'
app/views/performances/_show_banner.haml:12:in `block in _app_views_performances__show_banner_haml___933466686__622884308__332894942'
haml (3.1.4) lib/haml/helpers/action_view_mods.rb:93:in `block in capture_with_haml'
haml (3.1.4) lib/haml/helpers.rb:345:in `call'
haml (3.1.4) lib/haml/helpers.rb:345:in `block in capture_haml'
haml (3.1.4) lib/haml/helpers.rb:569:in `with_haml_buffer'
haml (3.1.4) lib/haml/helpers.rb:341:in `capture_haml'
haml (3.1.4) lib/haml/helpers/xss_mods.rb:61:in `capture_haml_with_haml_xss'
haml (3.1.4) lib/haml/helpers/action_view_mods.rb:93:in `capture_with_haml'
app/helpers/pretty_helper.rb:4:in `rounded_wrap'
app/views/performances/_show_banner.haml:4:in `_app_views_performances__show_banner_haml___933466686__622884308__332894942'
【问题讨论】:
-
title好像是空的。 -
命名路由是否声明在其等效资源声明之上?
标签: ruby-on-rails ruby ruby-on-rails-3 routes