Skip to content

Instantly share code, notes, and snippets.

@DrRobotmck
Created January 4, 2014 05:49
Show Gist options
  • Save DrRobotmck/8252182 to your computer and use it in GitHub Desktop.
Save DrRobotmck/8252182 to your computer and use it in GitHub Desktop.

The workflow we will follow looks like this:

  1. Planning
  2. Initializing Application
  3. Building the Rails Model
  4. Configure our Dev Environment
  5. Defining Routes
  6. Writing Controllers and their Views (iterate)
  7. Styling Views
  8. Share!

####Part one

Planning:

  • user stories
    • role, goal, reason
    • itemize features
    • define MVP (minimally-vaible-project)
  • create milestones
  • model data (draw ERD)
  • describe states (state diagram)
    • index, new, create, show
      • new -> CREATE (create) -> …
      • READ (index), READ (show)
    • edit, update, destroy
      • edit -> UPDATE (update) -> …
      • … -> DESTROY (destroy)
  • (wireframe -- not necessary here...)

####Part two

Initialize Application

  • rails new appname --database=postgresql
  • cd into appname, and then git init
  • git add / git commit

Building the Rails Model

  • create database (psql)
  • configure database.yml
  • define migration (rails generate migration)
    • column type string vs column type text et al
    • t.timestamps!
  • run migration
  • write model(s)
    • table is plural and snake_case; model class and file are both singular (in Camel and snake_ cases, respectively)
  • git commit!

Configure our Development Environment

At this point we want to make sure things are working, so let's test our model and database!

  • add what we want to our Gemfile ('pry-rails', 'better-errors', 'annotate', eg, all in group: development)
  • rails console (or rails c)
  • add some seed data…
    • appname/db/seeds.rb
    • rake db:seed
  • git commit!

####Part three

Define Routes

  • organize resources from model
  • non-resource-based routes (index)
  • git commit!

Write Controllers and their Views

  • add a controller and method
  • add the requisite view
  • git commit!
  • repeat!
  • often, a good order to write controller actions is:
    • Index (Displays all entries)
    • New (Displays a form to create a new entry)
    • Create (Creates a new entry and saves it to the database)
    • Show (Displays one particular entry)
  • continue:
    • Edit (Displays a form to edit an existing entry)
      • <form action="/resource" method="post"><input type="hidden" name="_method" value="put" />
      • Mimics "PUT"
    • Update (Updates an entry and saves it to the database)
    • Destroy (Deletes an entry)
      • <form action="/resource" method="post"><input type="hidden" name="_method" value="delete" />
      • Mimics "DELETE"

###Part four

Style

  • master stylesheet

Share!

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