I summarized the naming conventions for each Rails

When creating a Controller or Model with a command Is it singular or plural? So I summarized it

Overview

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.

Controller edition

** 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 edition

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

View

** Because there are multiple View files under the folder **, ** plural ** type

type Example Explanation
Folder name users Plural form

Routing edition

Routing ** resource name is based on Controller name **, so ** plural **

type Example Explanation
Resource name users Plural form

Reference article

https://diveintocode.jp/blogs/Technology/NamingRole

Recommended Posts

I summarized the naming conventions for each Rails
I summarized the display format of the JSON response of Rails
What should I use for the testing framework [Rails]
I summarized the collection framework.
I tried to introduce Bootstrap 4 to the Rails 6 app [for beginners]
Rails: I've summarized the model and database for a moment.
Rails model and table naming conventions
[Rails] I tried deleting the application
I made a reply function for the Rails Tutorial extension (Part 1)
[Rails] How to change the page title of the browser for each page
I made a reply function for the Rails Tutorial extension (Part 5):
I summarized the flow until implementing simple_calendar in Ruby on Rails.
Change the default timezone for the rails app
Prepare the security check environment for Rails 6
[Rails] Manage data for each seed file
[day: 5] I summarized the basics of Java
[Java] I personally summarized the basic grammar.
I tried using Docker for the first time
I rewrote the Rails tutorial test with RSpec
[Rails] When I use form_with, the screen freezes! ??
[Rails] I tried to raise the Rails version from 5.0 to 5.2
I tried to organize the session in Rails
Specify the timeout for each path with Rack :: Timeout
The code I used to connect Rails 3 to PostgreSQL 10
I tried touching Docker for the first time
[Rails] Naming convention
I changed the way Rails tutorials run: Rails Tutorial Notes-Chapter 9
[Rails] I learned about the difference between resources and resources
I made a check tool for the release module
[Each, map ...] I compared the array processing tonight [ruby]
[Rails] I tried playing with the comment send button
I tried using the Migration Toolkit for Application Binaries
[Rails] I don't know how to use the model ...
Challenge the settings for developing with vue.js on Rails 6
I introduced Docker to Rails 6, so I summarized it (beginner)
Note that I stumbled upon building the Rails environment
I summarized the types and basics of Java exceptions
I can't get out of the Rails dbconsole screen
[Rails] I investigated the difference between redirect_to and render.
I want to control the maximum file size in file upload for each URL in Spring Boot
I made a reply function for the Rails Tutorial extension (Part 4): A function that makes the user unique