Hackathon 2013/bootcamps

From TaxonWorks Wiki
Jump to: navigation, search

Rails Bootcamp


Clone the repository

git clone https://github.com/SpeciesFileGroup/taxonworks.git

Basic config

Run the bundler

 bundle install

Configure your database

Copy 'config/database.yml.example' to 'config/database.yml', edit the file to reflect your mysql/postgres username etc.

Setup the database

 rake db:drop
 rake db:create
 rake db:migrate

Run tests:


Run stuff

A console

 rails c 

A server

 rails s

Basic layout



Basic migrations

Practice first! (use '-p')

 rails generate model YourModel -p

Do it for real:

   rails generate model YourModel
   rails generate migration YourMigrationName

Migrations are created in db/migrate.

Edit them, (see Rails guides, or previous migrations). Lots of tricks are possible like:

  rails generate model YourModel field:integer field2:string

Run migrations with:

 rake db:migrate


Contain logic

class Foo < ActiveRecordBase

 belongs_to :bar
 has_many :blorfs



Contain view logic


Take requests (as defined in config/routes.rb), gather data, then direct to views.


Mix view and model logic.

Writing Code


1) Write a test. 2) Run the test, watch it fail. 3) Write some code.

Tests are in /spec.

Anyone can add a pending test:

context "sources does awesome stuff" do

 it "should do awesome stuff!"