As a Rails principle, there is a “contract over configuration”. There are conventions for naming rules (that is, how to name) class names and file names related to models, controllers, and views.
Names related to controller and view when controller name is “comments” are as follows.
Controller naming convention
| Name | Example | Rule | |:—————–|:——————|:——— ———-| |Controller class name |CommentsController | | Controller file name | comments_controller.rb | ○ ○ _controller.rb | |Template directory name |app/views/commnents |app/views/〇〇 |
The names when the model name is “comment” are as follows.
Model naming convention
| Name | Example | Rule | |:—————–|:——————|:——— ———-| | Database table name | comments | Begin with lowercase letters, plural | |Model class name |Comment |Uppercase is uppercase | | Model class file name | comment.rb | 〇〇.rb |
* If you want to name the database table name with two words, connect the words with underscores like
"shopping_carts". in this case,
- Controller class name: ShoppingCartsController
- Model class name: ShoppingCart
It becomes #####.