Tutorial by Examples

Controller class names are pluralized. The reason is the controller controls multiple instances of object instance. For Example: OrdersController would be the controller for an orders table. Rails will then look for the class definition in a file called orders_controller.rb in the /app/controllers ...
The model is named using the class naming convention of unbroken MixedCase and is always the singular of the table name. For Example: If a table was named orders, the associated model would be named Order For Example: If a table was named posts, the associated model would be named Post Rails will...
When a controller action is rendered, Rails will attempt to find a matching layout and view based on the name of the controller. Views and layouts are placed in the app/views directory. Given a request to the PeopleController#index action, Rails will search for: the layout called people in app/...
Rails files - and Ruby files in general - should be named with lower_snake_case filenames. E.g. app/controllers/application_controller.rb is the file that contains the ApplicationController class definition. Note that while PascalCase is used for class and module names, the files in which they r...
You can get a Model class from a Controller name this way (context is Controller class): class MyModelController < ActionController::Base # Returns corresponding model class for this controller # @return [ActiveRecord::Base] def corresponding_model_class # ... add some validation...

Page 1 of 1