rails singular resource still plural? rails singular resource still plural? ruby-on-rails ruby-on-rails

rails singular resource still plural?


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


Is the search really a resource? If it is, then what you a creating is an instance of a model with a type of "search", in which case the plural controller "searches" makes perfect sense.

However, if it's a controller that doesn't have multiple models, then maybe not. In which case, you don't need to define the routes with resource :search you can simply use get 'search/create' to tell the router to answer "search/create" to the 'create' action in your 'search' controller.