Show Menu
Cheatography

Rails - ROR Cheat Sheet (DRAFT) by

Revising the concepts

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Create first app

rails new name
rails --version

Creating a Database Model

rails g model Product name:s­tring
rails db:migrate

Change database to add or remove tables

..

Console

Rails.v­ersion
User.c­olu­mn_­names
See columns in user table
user = User.new()
Create a user
user.save
save the user
user
To see the details of user
user = User.c­reate()
User.all
User.w­her­e(name: 'name')
User.o­rde­r(name: :asc)
User.f­ind(12)
user.u­pda­te(­name: "­BC")
user.save
user.d­estroy

new vs create

new - builds new User, not save to db. You need to call save object
create - Builds a new Product object and immedi­ately saves it to the database (runs valida­tions).