Saturday, April 02, 2011

Starting a rails project

This is just a quick reminder about how to start a standard rails project. The assumption is that rvm already installed on an Ubuntu machine (I'm using Natty).
  • mkdir projects
  • cd projects
  • rails new project_name -T
  • echo "rvm --create use 1.9.2@project_name" > .rvmrc
  • cd project_name
  • (agree to the use of the .rvmrc file)
My default Gemfile at the moment takes into account that I'll be creating a general API and will be using rspec (I tend to use rspec for integration testing too). It includes spork and autotest for a cool autotest environment.
  • (create the following Gemfile)
  • gem install bundler
  • bundle install
source ''

gem 'rails', '3.0.1'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
gem 'gravatar_image_tag', '0.1.0'
gem 'will_paginate', '3.0.pre2'

group :development do
gem 'rspec-rails', '2.0.1'
gem 'annotate-models', '1.0.4'
gem 'faker', '0.3.1'

group :test do
gem 'rspec', '2.0.1'
gem 'webrat', '0.7.1'
gem 'spork', '0.9.0.rc4'
gem 'libnotify', '0.3.0'
gem 'factory_girl_rails', '1.0'
Add the inital state of the framework to git. Take the opportunity to create a project at github and upload your public key (so that you can push up the project).
  • git init
  • git add .
  • git commit -am "Initial commit of Rails framework"
  • git remote add origin
  • git push origin master
Then create a project at heroku (goto and sign up) - you may need to install the heroku gem (gem install heroku)
  • heroku create
  • git push heroku master
  • heroku rename project-name #you can't use _ so, I tend to use - instead here
Finally, it's time to get rspec installed
  • rails generate rspec:install
Get some generate setup done for static pages:
  • remove public/index.html
  • add public/stylesheet/blueprint
  • add public/stylesheet/custom.css #see rails3tutorial
  • rails generate controller Pages home contact about
Add some autotesting
  • sudo apt-get install libnotify-bin
  • echo "require 'autotest/growl'" >> .autotest
  • spork --bootstrap
  • edit spec/spec_helper.rb to contain the contents of Listing 3.13 from the Rails3Tutorial Book
  • echo "--drb" >> .rspec
  • create /usr/local/bin/runautotest
sleep 10s
  • sudo chmod +x /usr/local/bin/runautotest

No comments: