Skip to content

Instantly share code, notes, and snippets.

@nizaroni
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save nizaroni/425fd2d426edd6fcbf3d to your computer and use it in GitHub Desktop.

Select an option

Save nizaroni/425fd2d426edd6fcbf3d to your computer and use it in GitHub Desktop.

New Project

Create the project

These all do the same thing:

rails new pizza-project --skip-bundle --skip-test-unit --skip-turbolinks --database=postgresql
rails new pizza-project -B -T -d postgresql --skip-turbolinks
rails new pizza-project -BTd postgresql --skip-turbolinks

NOTE: This creates the project folder so you don't have to create it beforehand.

Navigate into the project folder

cd pizza-project

Create your database

Make sure your database server (usually Postgres) is running.

rake db:create

Get to work

Normal Routes

  1. Make a route
  2. Make a controller
rails generate controller YourControllerName action1 another_action more_action
rails generate controller your_controller_name action1 another_action more_action

NOTE: This will add routes automatically. You may want to alter them.

  1. Your view is already created. Modify it!

Model Routes (a.k.a. resources)

  1. Add resources :plural_model_name to routes
  2. Generate the model.
rails generate model YourModelName name:string price:float size:string description:text
  1. Modify your migration (if necessary).
  2. rake db:migrate
  3. Implement actions as needed (new, create, index, etc.).

Altering your models

Make a new migration:

rails generate migration add_calories_to_salads calories:integer

Utilities

rake routes - lists current routes

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