All filenames are in snake_case following the same conventions
- Model: singular (e.g.
Restaurant
) - Controller: plural (e.g.
RestaurantsController
) - Table in DB: plural (e.g.
restaurants
) - URL's: all in plural (e.g.
/restaurants
,/restaurants/:id
,/restaurants/new
)
- Create model: singular (because the name of the model is singular). e.g.
rails g model
Restaurant
name:string rating:integer
- Create migration: plural (because we use the name of the table). e.g.
rails g migration AddDescriptionTo
Restaurants
description:text
- Create controller: plural e.g.
rails g controller
Restaurants
index show
All in singular, because all ActiveRecord
's methods are linked to the model.
Examples:
Restaurant.all
Restaurant.create(name: "Burger King", rating: 2)
Restaurant.find(params[:id])
- Singular in the
belongs_to
. Because it belongs to one element. - Plural in the
has_many
. Because it has many elements.
e.g.
class Restaurant < ActiveRecord::Base
has_many :reviews
end
class Review < ActiveRecord::Base
belongs_to :restaurant
end
Plural when defining a route for a resource:
resources :restaurants
index
: plural (because we are showing a list of elements). e.g.restaurants_path
. Can also be used used forcreate
.show
: singular (we are showing just one element, it needs the element inside parenthesis). e.g.restaurant_path(@restaurant)
. Can also be used forupdate
&delete
.new
: singular. e.g.new_restaurant_path