We all suffer from the stress that comes with realizing that you named something correctly but didn't follow the right convention... its 2020.. Let's put that stress to an end!
Below ill give you a summary for ruby/rails naming conventions..
We'll start with general ones than go into filesystem related conventions!
Ruby
(Class names) are CamelCase.
(Methods) and (variables) are snake_case.
Database
+--------------------------+
| top_food_spots |
+------------+-------------+
| id | ID |
| sighted_at | DATETIME |
| location | STRING |
+------------+-------------+
+------------------------------+
| Users |
+---------------------+--------+
| id | ID |
| name | STRING |
+---------------------+--------+
(Database tables) = snake_case.
(Table names) = plural.
(Column names) in the database = snake_case (but are generally singular.)
Model
(Model class names) = CamelCase.
These are singular, and will be writting automatically to the plural database table name.
(Model attributes and methods) = snake_case
and match the column names in the database.
**
app/models/bigfoot_sighting.rb
class TopFoodSpots < ActiveRecord::Base
# This class will have these attributes: id, sighted_at, location
end
**
Controllers
(Controller class names) = CamelCase
but (The Controller suffix) is always singular. The name of the resource is usually plural.
(Controller actions) = snake_case
and usually match the standard route names Rails defines
(index, show, new, create, edit, update, delete).
app/controllers/profiles_controller.rb
ProfilesController < ApplicationController
def show
# ...
end
# etc
end
Top comments (1)
Checkout rubocop for a nice reference of style guides ;-)