Why Controller names are plural but application_controller is itself a singular.
I was just curious when i scaffold a person and rails generated a people_controller for it, I was impressed but then I saw application_controller and it is singular. Does it has an explanation or it is as it is ?
CodePudding user response:
Rails is full of conventions and plural names for controllers is simply one of those conventions. It is so Rails can locate the appropriate controller when you put resources :books
in your routes.rb
You can override the convention and specify the controller explicitly, resources :books, controller: "library"
. In this case, Rails will look for LibraryController
.
With ApplicationController
, you don't call it directly and Rails doesn't need to do this lookup and so it can be named whatever. You can rename it, for example.