We’re converting our Rails 2.3 app to 3.0.11, and were having a problem migrating some of the routes.
To me, it appears our custom parameters (:title and :name_recognition) are causing some problems. However, we are using named routes so I’m very unclear why Rails is trying to do any matching by controller, action, and parameters at all.
Error we get:
ActionView::Template::Error (No route matches {:controller=>"audience_tool", :action=>"show", :name_recognition=>"BandName", :title=>"", :id=>1388}):
This is route in question from routes.rb:
match ':name_recognition/:title/:id' => 'audience_tool#show', :as => :show_page
Here is result from “rake routes”:
show_page /:name_recognition/:title/:id {controller=>"audience_tool", :action=>"show"}
Here is the model method that we use to build the URL:
def url(options=Hash.new)
options.reverse_merge!({
:name_recognition => name_recognition,
:title => title,
:id => id
})
show_page_path options
end
Here is how we call the method:
link_to("The Link text", show.url)
Stack Trace, minus the template code that gets displayed in the error:
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'
blank title attribute inside parameter is the problem
dynamic parameter routes declared as –
now go to the rails console –
above route expects each parameter inside url to be present.
If you are too sure that certain parameter can be blank then you can define it as optional parameter inside route –