Difference between revisions of "Hackathon 2013/bootcamps"
(Created page with "Rails Bootcamp ============== Clone the repository git clone https://github.com/SpeciesFileGroup/taxonworks.git Basic config ------------ Run the bundler bundle instal...") |
Latest revision as of 12:01, 1 October 2013
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:
rake
Run stuff
A console
rails c
A server
rails s
Basic layout
app/models
/controllers /views /helpers
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
Models
Contain logic
class Foo < ActiveRecordBase
belongs_to :bar has_many :blorfs
end
Views
Contain view logic
Controllers
Take requests (as defined in config/routes.rb), gather data, then direct to views.
Helpers
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!"
end