Rails 3.1 Dev Setup

08 August 2011 - 18:37
Permalink

Now that Rails 3.1 is nearing release, we’ve finally decided to migrate from 2.x development into the sunshine of the new Rails 3 world. We’re less embarrassed to be such late adopters than perhaps we should be, since at last year’s Golden Gate Ruby Conference at least half the people we talked with hadn’t yet started to move to Rails 3. But the time finally now seems right.

References and Resources

Beyond the infinite sources of tips and explanations about Rails 3 that Google reveals, here are some references that we’ve found to be particularly useful:

What is missing right now is an updated version of Deploying Rails Applications, since the old nginx-mongrels stack has fallen out of favor (and indeed mongrel doesn’t appear to work at all with the new rack-based middleware in Rails 3).

Project Setup

The ecosystem of Rails development has become particularly lush during the past couple of years.

RVM and Rails Bootstrap

Rails 3 requires Ruby 1.9.x whereas Rails 2 used Ruby 1.8.7 — so Ruby version management is now crucial when making the transition. Fortunately, the insanely useful Ruby Version Manager makes it very easy to control exactly which version of Ruby and which versions of all gems a given project uses through the creation of gemsets.

To bootstrap a new Rails 3.1 project, you need to install a basic Rails into a general gemset:

$ gem install rails --pre # this will change once 3.1 is finally released

Then here’s the bare-bones outline of how to setup a new project (once rvm is installed of course and assuming you sensibly want to use PG as the DB):

$ mkdir -p /path/to/projects/new_project $ rvm gemset create new_project $ cd new_project $ echo "rvm use 1.9.2@new_project --create" > .rvmrc $ rails new . --git --database=postgresql

In order to make bundler run the right versions of the executables (see this), add “export PATH=./bin:$PATH” to the .rvmrc file.

The .rvmrc file generates this useful confirmation any time you cd into the directory:

Using /your/path/.rvm/gems/ruby-1.9.2-p180 with gemset new_project

Textmate

Textmate remains a great editor for all Rails development with great bundles for git and rspec.

Gemfile

Here’s a initial Gemfile for a beginning project:

source "http://rubygems.org" source "http://gems.github.com/"

gem “rails”, “3.1.0.rc5”
gem “pg”
gem “sass-rails”, “~> 3.1.0.rc”
gem “coffee-script”
gem “uglifier”
gem “jquery-rails”
gem “unicorn”

  1. gem “capistrano”
  2. gem “ruby-debug19”, :require => “ruby-debug”
    gem “cancan”
    gem “devise”

group :test do
gem “turn”, :require => false
gem “factory_girl_rails”
gem “capybara”
gem “fakeweb”
gem “database_cleaner”
gem “timecop”
gem “spork”, “~> 0.9.0.rc”
end

group :development, :test do
gem “rspec-rails”
gem “autotest”
gem “launchy”
end

This assumes use of Postgresql, unicorn, Rspec and ancillary tools like capybara, launchy and autotest — though not cucumber. With this setup, we’re ready to roll.

Comments

No comments yet.

To comment, you must log in first.


Latest News

Musings, reports, and notes to ourselves about technical matters of importance.