[Rails] Naming convention

As a principle of Rails, there is ** "Convention over configuration" **. There are conventions for naming conventions (that is, naming conventions) for class names and filenames for models, controllers, and views.

The names related to the controller and view when the controller name is "comments" are as follows.

Controller naming convention

name Example rule
Controller class name CommentsController 〇〇Controller, capital letters at the beginning
Controller file name comments_controller.rb 〇〇_controller.rb
Template directory name app/views/commnents app/views/〇〇

The name when the model name is "comment" is as follows.

Model naming convention

name Example rule
Database table name comments Start with lowercase letters, plural
Model class name Comment Uppercase at the beginning
Model class filename comment.rb 〇〇.rb
* If you want to give the database table name a name consisting of two words, connect the words with an underscore like " shopping_carts ". in this case,

--Controller class name: ShoppingCartsController --Model class name: ShoppingCart

Will be.

Recommended Posts

[Rails] Naming convention
Collection variable naming convention
boolean method naming convention
About naming Rails model methods
Rails model and table naming conventions
Naming convention when creating a new controller or model with rails
[Rails g.error]
Rails basics
Rails Review 1
Rails API
Rails migration
[Rails] first_or_initialize
rails tutorial
About Rails 6
Rails foundation
Rails memorandum
rails tutorial
rails tutorial
rails tutorial
[Rails] devise
rails tutorial
rails tutorial
Rails Tips
rails method
rails tutorial
[Rails] ActiveRecord
[Rails] form_with
Rails Review 2
I summarized the naming conventions for each Rails
Explanation of Ruby on rails for beginners ④ ~ Naming convention and how to use form_Tag ~