Skip to content

Instantly share code, notes, and snippets.

@danbroadbent
Last active September 11, 2016 16:30
Show Gist options
  • Save danbroadbent/1deb1fd398211f1fca5765cd299c27b2 to your computer and use it in GitHub Desktop.
Save danbroadbent/1deb1fd398211f1fca5765cd299c27b2 to your computer and use it in GitHub Desktop.
Rails Command Line Cheat Sheet:

#Rails Command Line Cheat Sheet:

Create a New Rails App: $ rails new “app_name_goes_here”

Create a New Rails App w/ Postgres Database: $ rails new “app_name_goes_here” -d=postgresql
Create a New Rails App w/o Minitest: $ rails new “app_name_goes_here” -T

If you add a new gem, don’t forget to $ bundle install

Show all existing routes: $ rake routes

Open Rails Console: $ rails console

Setup Database (create database, load the schema, initialize it with seed data): $ rails db:setup
Reset Database: $ rails db:reset (equivalent to rails db:drop db:setup)
Run Migrations: $ rake db:migrate

Start Rails Server: $ rails s OR $ rails server

###Generating Migrations from the command line (the command is in the “”):
Create a table: $ “rails g migration CreateYYY” where YYY is the name of the table you want to create

Create a table with columns: $ “rails g migration CreateYYY XXX:datatype ZZZ:datatype” where XXX and ZZZ are columns, and YYY is the table

Add a column to a table: $ “rails g migration AddXXXToYYY XXX:datatype” where XXX is the column, and YYY is the table

Remove a column from a table: $ “rails g migration RemoveXXXFromYYY XXX:datatype” where XXX is the column, and YYY is the table

Add a reference column to a table: $ “rails g migration AddAAARefToBBB AAA(singular):references” where AAA is the table supplying the foreign key to be inserted into the BBB table

Create a join table: $ “rails g migration CreateJoinTableXXXYYY XXX YYY” where XXX and YYY are the two tables supplying the foreign keys to the join table

Rollback Migration: $ rails db:rollback

Routes:
resources :items, only: [:show, :index]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment