named my_awesome_app with postgresql -d=postgresql but skip making a git repository -G & tests boilerplate -T:
rails new my_awesome_app -d=postgresql -GT
cd my_awesome_app
rails db:create
commonly used generators are the resource generator, model generator & migration generator
rails generate resource product name:string description:text
generate a model, a controller and a migration file boilerplate
rails generate model product name:string description:text
generate a model and a migration file boilerplate
rails generate migration add_user_id_to_products user:references
generate a migration file that adds a foreign key user_id to the products table
rails db:migrate
controller name and view folder name are based on your route
get '/things', to: 'products#index'the controller name will be products, the method inside the controller will be index, the index.html.erb will be in a sub folder named products and the controller filename will be products_controller.rb
class ProductsController < ApplicationController
def index
end
endview template for index /views/products/index.html.erb
model file product.rb and filename: always singular
class Product < ApplicationRecord
end