Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Resource controller name pluralization regression

#4980

In Rails 2.3 the controller name is not forced to be a plural in a map.resources call, e.g:

map.resources :content

creates routes like this:

andyw$ rake routes
             GET    /content(.:format)          {:action=>"index", :controller=>"content"}
    contents POST   /content(.:format)          {:action=>"create", :controller=>"content"}
 new_content GET    /content/new(.:format)      {:action=>"new", :controller=>"content"}
             GET    /content/:id(.:format)      {:action=>"show", :controller=>"content"}
             PUT    /content/:id(.:format)      {:action=>"update", :controller=>"content"}
     content DELETE /content/:id(.:format)      {:action=>"destroy", :controller=>"content"}
edit_content GET    /content/:id/edit(.:format) {:action=>"edit", :controller=>"content"}

Whereas in 3.0:

resources :content

creates routes like this:

andyw$ rake routes
             GET    /content(.:format)          {:controller=>"contents", :action=>"index"}
    contents POST   /content(.:format)          {:controller=>"contents", :action=>"create"}
 new_content GET    /content/new(.:format)      {:controller=>"contents", :action=>"new"}
             GET    /content/:id(.:format)      {:controller=>"contents", :action=>"show"}
             PUT    /content/:id(.:format)      {:controller=>"contents", :action=>"update"}
     content DELETE /content/:id(.:format)      {:controller=>"contents", :action=>"destroy"}
edit_content GET    /content/:id/edit(.:format) {:controller=>"contents", :action=>"edit"}

The attached patch restores this behaviour.

Reported by Andrew White · June 26th, 2010 @ 08:24 AM

State: resolved
Milestone: 3.0.2
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: High

Activity

  1. Repository
    Repository
    • State changed from open to resolved

    (from [9a6fc9a540cd23af3ca061cb7406a6cdd5ad4294]) Don't force pluralization of controller name when defining a resource [#4980 Resource controller name pluralization regression state:resolved]

    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/9a6fc9a540cd23af3ca061cb7406a6...

    June 26th, 2010 @ 11:10 AM

  2. Jeremy Kemper
  3. Romain
    Romain

    Is it just me or is the very same bug still present in 3.0.3 on "map.resource" ?
    For some reason,

    resource :admin, :only => [:show]
    

    results in the following "rake routes" output :

           admin GET    /admin(.:format)                       {:controller=>"admins", :action=>"show"}
    

    Notice how the "controller" name is pluralized (which IMHO makes even less sense since it's a singular resource).

    January 13th, 2011 @ 10:42 AM

  4. David Phillips
    David Phillips

    It seems intentional that singular resources pluralize the controller name. The routing guide has this note:

    Because you might want to use the same controller for a singular route (/account) and a plural route (/accounts/45), singular resources map to plural controllers.

    March 3rd, 2011 @ 10:33 PM

  5. David Phillips
    David Phillips

    I agree that pluralization by default rarely makes sense for singular resources, but unfortunately, it probably can't be changed now due to backwards compatibility.

    March 3rd, 2011 @ 10:39 PM