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
Declaring a resource or resources generally corresponds to generating many default routes. resource is singular. resources is plural.
Difference between singular resource and resources in Rails routes. So far, we have been using resources to declare a resource. Rails also lets us declare a singular version of it using resource. Rails recommends us to use singular resource when we do not have an identifier.
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
You could fix this by setting the plural of "search" to be uncountable so in config/initializers/inflections.rb
ActiveSupport::Inflector.inflections do |inflect| inflect.uncountable %w( search ) end
This should now allow search to only be used
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With