Rails 3.1 Dev Setup
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:
- Ryan Bates’ RailsCasts — prescient overview of what is cool and optimal
- The Rails 3 Way book — by Obie Fernandez, an excellent reference to the APIs
- The Rails 3 in Action book — by Yehuda Katz and Ryan A. Bigg, though mostly if not completely by Ryan — emphasizes the Behavior Driven Development approach that is now all the rage
- The RSpec Book — by David Chelimsky et al., the definitive guide
- Travis Swicegood’s two Git books — Pragmatic Guide to Git and Pragmatic Version Control Using Git
- Continuous Testing — by Ben Rady and Rod Coffin
- The Cucumber Book — by Matt Wynne and Aslak Hellesøy, though we’re not fans of Cucumber (to be discussed at some later date)
- Installation Guide — by Daniel Kehoe at github, showing how to upgrade to newer versions of ruby
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 SetupThe 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
$ 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 remains a great editor for all Rails development with great bundles for git and rspec.
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" # gem "capistrano" # 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.