rails singular resource still plural?

holden picture holden · Aug 4, 2011 · Viewed 25.5k times · Source

I have a search route which I would like to make singular but when I specify a singular route it still makes plural controller routes, is this how it's supposed to be?

resource :search

Gives me

 search POST        /search(.:format)        {:action=>"create", :controller=>"searches"}
 new_search  GET    /search/new(.:format)    {:action=>"new", :controller=>"searches"}
 edit_search GET    /search/edit(.:format)   {:action=>"edit", :controller=>"searches"}
             GET    /search(.:format)        {:action=>"show", :controller=>"searches"}
             PUT    /search(.:format)        {:action=>"update", :controller=>"searches"}
             DELETE /search(.:format)        {:action=>"destroy", :controller=>"searches"}

Plural controller "searches"

I only have one route really... to create a search:

So I did: match "search" => "search#create"

I'm just wondering for the future if I'm still supposed to keep the controller plural? Rails 3.0.9

Answer

M. Cypher picture M. Cypher · Aug 4, 2011

Yes, that's how it's supposed to be. Quote from the Rails Guide on Routing:

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.

http://edgeguides.rubyonrails.org/routing.html#singular-resources