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.

Here’s a diff against the 1.2 branch of Rails that allows you to see all the generated routes as they are read: For reference, here are all the generated routes for this declaration:
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

 

Search

A picture of me

I am François Beausoleil, a Ruby on Rails coder. During the day, I work on XLsuite. At night, I am interested many things. Read my biography

Tags

(4) (1) (1) (1) (1) (2) (1) (1) (1) (2) (2) (1) (2) (1) (3) (1) (2) (1) (1) (1) (1) (2) (14) (1) (1) (1) (1) (2) (1) (1) (2) (0) (1) (4) (1) (3) (1) (1) (1) (1) (1) (1) (0) (3) (2) (1) (2) (1) (3) (1) (5) (2) (10) (10) (11) (14) (2) (1) (3) (1) (1) (1) (1) (1) (0) (1) (2) (2) (2) (1) (1) (1) (4) (1) (3) (1) (4) (2) (2) (25) (2) (1) (1) (0) (1) (1) (1) (23) (25) (1) (1) (13) (1) (1) (1) (4) (5) (1) (1) (1) (4) (1) (2) (3) (4) (4) (1) (1) (1) (8) (3) (1) (5) (5) (2) (2) (2) (4) (8) (7) (1) (1) (1) (1) (2) (4) (1) (4) (12) (2) (1) (2) (4) (1) (1) (1) (2) (8) (2) (3) (2) (2) (1) (3) (1) (1)

Links

Projects I work on

Categories

Archives