Rails中的单数或复数控制器和助手名称

问题描述:

对于控制器和助手使用单数名称是否有任何不利之处?似乎没有任何依赖.甚至看来,助手至少在我有限的实验中,不必对单数或复数与其相应的控制器进行相同的选择.是真的吗?

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?

肯定是复数.

控制器:

dog_controller.rb  

路线:

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

路线:

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

rails generate controller --help包含多个示例:

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