This project is archived and is in readonly mode.

#5820 ✓invalid
inetufo

Singular Resource mapping to plural controller in rails 3

Reported by inetufo | October 16th, 2010 @ 08:26 AM

resources :users do

  resource :wall do
    post :add_comment
  end
end

end

and the route generated is

user_wall POST /users/:user_id/wall(.:format) {:controller=>"walls", :action=>"create"}

new_user_wall GET /users/:user_id/wall/new(.:format) {:controller=>"walls", :action=>"new"}

edit_user_wall GET /users/:user_id/wall/edit(.:format) {:controller=>"walls", :action=>"edit"}

user_wall GET /users/:user_id/wall(.:format) {:controller=>"walls", :action=>"show"}

user_wall PUT /users/:user_id/wall(.:format) {:controller=>"walls", :action=>"update"}

user_wall DELETE /users/:user_id/wall(.:format) {:controller=>"walls", :action=>"destroy"}

Why the Singular Resource maps to plural controller "walls" not the singular form "wall"
Is this a bug ?

Comments and changes to this ticket

  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer October 16th, 2010 @ 08:40 AM

    • State changed from “new” to “invalid”
    • Importance changed from “” to “Low”

    No, that's not a bug. Controllers are always plural, singular routes are just a way to route to without having to specify an ID. Check out the Routing guide:

    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.

    Marking this as invalid, thanks for letting us know though. :)

  • inetufo

    inetufo October 16th, 2010 @ 09:17 AM

    Thanks for the reply, but in my situation, a user just has one wall.I mean the url is like http://xxx/user/:user_id/wall, and will never be http://xxx/user/:user_id/wall/:id, the "wall" contoller is just used to show something just like comments to a user, and will never have an id param.Howerver, i changed the controller name to WallsController, and it works, but it looks a little weird...Any other way to write this?

  • inetufo

    inetufo October 17th, 2010 @ 04:12 PM

    I found a solution already by specifying the :controller param

    resources :users do

    resource :wall, :controller => "wall" do

    post :add_comment
    

    end end

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages