When creating a Controller or Model with a command Is it singular or plural? So I summarized it
In Rails One of the basic principles ** CoC (Convention over Configuration) ** is defined
CoC does not have to be conscious of beginners
Not only does it save you from pondering, it also fosters a deeper abstraction
Is written in the article Quote
In other words, reduce and simplify developer decisions.
** Because it has multiple actions **, ** multiple ** series
type | Example | Explanation |
---|---|---|
Controller name | users | Plural form |
file name | blogs_controller.rb | Plural form |
Controller class name | UsersController | Camel case |
command | rails g controller users | Plural form |
app/controllers/users_controller.rb
class UsersController < ApplicationController
def index
end
end
Model is like a design document ** One design document **, so ** singular **
** Plural ** form because the table holds multiple pieces of information ** Because migration files and classes create tables In that regard, the same ** plural ** form
type | Example | Explanation |
---|---|---|
Model name | user | Singular |
file name | blog.rb | Singular |
Model class name | User | Singular, capital letters |
Table name name | users | Plural form |
Migration file name | ☓☓☓_create_users.rb | Plural form |
command | rails g model User | Singular |
app/models/user.rb
class User < ApplicationRecord
has_many :articles
end
db/migrate/2020☓☓☓_create_users.rb
class CreateUsers < ActiveRecord::Migration[5.2]
def change
create_table :users do |t|
t.string :name
t.string :email
t.timestamps
end
end
end
** Because there are multiple View files under the folder **, ** plural ** type
type | Example | Explanation |
---|---|---|
Folder name | users | Plural form |
Routing ** resource name is based on Controller name **, so ** plural **
type | Example | Explanation |
---|---|---|
Resource name | users | Plural form |
https://diveintocode.jp/blogs/Technology/NamingRole
Recommended Posts