Singular or plural controller and helper names in Rails

allyourcode picture allyourcode · Mar 15, 2009 · Viewed 66.6k times · Source

Is there any disadvantage to using singular names for controllers and helpers? Nothing seems to rely on this. It even seems helpers don't have to make the same choice about singular vs. plural as their corresponding controllers, at least according to my limited experimentation. Is that true?

Answer

jpgeek picture jpgeek · Oct 1, 2010

Definitely plural.

With restful routing and a singular controller

Controller:

dog_controller.rb  

Routes:

map.resources :dogs  # => blows up  
map.resources :dog  # is ok, but...  
dogs_path # => blows up  
dog_path  # => ok  

Using a plural controller

Controller:

dogs_controller.rb

Routes:

map.resources :dogs  
dogs_path # => ok  
dog_path # => ok  

rails generate controller --help has plural examples:

Example:
`rails generate controller CreditCards open debit credit close`

CreditCards controller with URLs like /credit_cards/debit.
    Controller: app/controllers/credit_cards_controller.rb
    Test:       test/controllers/credit_cards_controller_test.rb
    Views:      app/views/credit_cards/debit.html.erb [...]
    Helper:     app/helpers/credit_cards_helper.rb