Skip to content

skygroundmedia/rails-5-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

Ruby Version 5.0

  • System dependencies

  • Configuration

  • Database creation

  • Database initialization

  • How to run the test suite

  • Services (job queues, cache servers, search engines, etc.)

  • Deployment instructions

Commands


Create a new rails app

rails new cheatsheet -d postgresql

Add gems to Gemfile

Install Gem

bundle install

Install devise

rails g devise:install

Folow devise instructions

Create vanilla rails controller

rails g controller home index

Create the Devise model

rails g devise User

Create the Devise view

rails db:create db:migrate
rails g devise:views

Add this code fragment to /app/models/user.rb.

before_action :authenticate_user!  
#user:belongs_to could also be written user:references
rails g model vendor user:belongs_to first_name:string last_name:string gender:string birthdate:date occuptation:string city:string state:string zip_code:string --force

Controllers

Create a vanilla home controller

rails g controller home index

Tasks

Run a server using a custom task

rails server:start

Custom task to wipe the database

rails db:wipe



Validate a Ranking

validates_numericality_of :rating, :greater_than_or_equal_to => 0.0, :less_than_or_equal_to => 10.0