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?
Singular or plural scope names in Rails
I have a question in my head. Is there any disadvantage to using singular or plurial in names for scope ? I found nothing on the question. Sometimes I put in the plural to help me understand the real
Ruby on Rails plural (controller) and singular (model) convention – explanation
As per Ruby on Rails convention, controller names get pluralized while model names are singular. Example : a Users controller, but a User model. rails generate controller Users rails generate model Us
Singular or plural database table names? [duplicate]
Exact Duplicate Table Naming Dilemma: Singular vs. Plural Names Is it better to use singular or plural database table names ? Is there an accepted standard ? I’ve heard arguments for and against it,
rails singular resource still plural?
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 sear
plural/singular controller name [closed]
I know that using plural for controllers name is the right way in Ruby, but in some cases using singular for controllers name is more appropriately. For example http://foobar.com/admin/login/ http://f
Ruby on Rails: How do you explicitly define plural names and singular names in Rails?
For example, I’m using Bonus as my model, so I’d expect bonuses to be the plural form and bonus to be the singular form. However, in Ruby, this results in: bonus.pluralize # bonus bonuses.si
Why would you want to use the same controller to handle a singular and a plural route?
I’m working on a rails app and using a singular resource. However the controller name for the singular resource is plural. Eg map.resource activity_report expectes the activity_reports_controller. Th
Is there a plural/singular reference list for Rails?
Ruby on Rails has many different generators and other such things. In my experience, the naming is hardly ever obvious though for if you should use a singular or plural name. For instance for the Cont
What’s the Rails way to handle singular/plural possibility?
When you present a message to the user that involves an entity that could be either singular or plural, Rails has a shortcut to handle that. I’m talking about this situation: Delete committee? Its X
Rails HomeController singular or plural?
I’ve been configuring my devise installation and I came upon the line of: root to: ‘home#index’ From my understanding, I thought controllers were to be named plural. Is HomeController just an excepti
Using plural names for controllers is just a convention.
Plural names usually sound more natural (especially for controllers that are tied directly to a specific model: User -> Users, etc.), but you can use whatever you want.
As for helpers, all helpers are available for all controllers by default, so technically, how you name your helpers doesn’t matter at all. It’s just another convention to keep a controller’s helper functions in a helper with the same name as the controller.
Using plurals just sounds better, and then if you have a controller that handles a singular resourse, ie user, then you can still name the url /user.
With helpers there is often no need to have a helper for every controller, and often there will be helper methods you can use ascorss multiple controllers and rather litter them all through your application helper you could put them in custom helpers instead like eg layout_helper or any other well named file.
I feel better when I use singular for Controller name
A Model is singular because it references a single object like User. A controller is plural because it is the controls (methods) for the collection of Users. How one names the routes is all up to that individual developer. I’ve never had a user complain that a URL for a web request is singular or plural. The end result to maintain a common convention for current and future contributors while serving quality page displays or the API requests for the end users.
With restful routing and a singular controller
map.resources :dogs # => blows up map.resources :dog # is ok, but... dogs_path # => blows up dog_path # => ok
Using a plural controller
map.resources :dogs dogs_path # => ok dog_path # => ok
rails generate controller –help has singular examples though. Ugh.
You have a very complete explanation in the Rails guides: http://edgeguides.rubyonrails.org/routing.html#resource-routing-the-rails-default
It is the Rails convention that one controller handles one model, whether one or more instances of that model can exist during runtime. However, you can have a Rails application where (some of) the controllers (and the associated views) are not associated with any particular model, but rather handle a more complex set of functionality. In this case, the automatic pluralization doesn’t make any sense.
The Rails application I’m currently working on fits into this category, and it’s simply an irritation to me that Rails expects that the identifiers I define as a singular in one place are then used in their plural forms in other places. For example, I might want to define something like this in config/routes.rb:
resource :dashboard, :only => [:show]
and then I want a controller DashboardController to display summary information about certain aspects of the application, gathering information from more than one database table. So here, Dashboard does not refer to any model of the application, and it would be just weird to have the controller’s name be DashboardsController.
I found a good solution to the irritation of automatic pluralization in this answer. In short, edit file config/initializers/inflections.rb and add the words you don’t want to be automatically pluralized to this definition:
ActiveSupport::Inflector.inflections do |inflect| inflect.uncountable %w( dashboard foo bar baz ) end
If the controller is a resource then it must be plural…
But you can use singular controller names when you do not have corresponding models like
The naming convention of controllers in Rails favors pluralization of the last word in the controller’s name, although it is not strictly required (e.g. ApplicationController).
For example, ClientsController is preferable to ClientController, SiteAdminsController is preferable to SiteAdminController or SitesAdminsController, and so on.
Following this convention will allow you to use the default route generators (e.g. resources, etc) without needing to qualify each :path or :controller, and will keep URL and path helpers’ usage consistent throughout your application.