Named resources with name prefixes
March 14th, 2007
Rails allows you to define routes with named prefixes. I expected Rails to somehow know that I wanted my prefix to separate the rest of the name with an underscore.
Here was my original routes: Then, when I tried to use my route, I was getting a NoMethodError:After a bit of sleuthing (and adding messages to ActionController::Routing::RouteSet#add_named_route), I found out that I was supposed to put the underscore myself on the prefix, like this:
It was also interesting to see all those generated routes. I discovered that the route with a format was named formatted_whatever.
layouts => "/admin/layouts" formatted_layouts => "/admin/layouts.:format" new_layout => "/admin/layouts/new" formatted_new_layout => "/admin/layouts/new.:format" edit_layout => "/admin/layouts/:id;edit" formatted_edit_layout => "/admin/layouts/:id.:format;edit" layout => "/admin/layouts/:id" formatted_layout => "/admin/layouts/:id.:format"
EDIT* (2007-03-14 16:52 EDT): Changed link to routing.rb file to the Rails Trac Browser.
Leave a Reply