Rails 3: getting started

Rails 3 Cliff Notes, Part 1: getting started

  1. Requires Ruby 1.8.7 or higher, but Ruby 1.9.2 is very stable and you should use it for new projects (unless you deploy on Heroku). Use rvm to remain sane when switching between new and old projects. By creating a .rvmrc file, rvm will automatically switch you to the right version of Ruby and set of gems when you cd into the directory.
  2. Heroku requires 1.8.7 for Rails 3. To create a heroku app for rails 3, you need to use the “bamboo” stack
    heroku create --stack bamboo-ree-1.8.7
  3. You must use bundler which means that the only gems that Rails will use are the ones declared in your Gemfile. Very cool.
    • I plan to use Heroku, so I want to make sure that I’m only using sqlite3 in development and test.
    • I like rspec, so I also add it to my Gemfile (added to development as well as test, so I can use generators
    • Update: if you scaffold and rspec generates view specs, it will use webrat steps, but there is no gem dependency, you need to add webrat to the Gemfile
  4. No more script/console, use the rails command for everything
  5. Set up the test framework that you like first, then the rails generators will create the correct corresponding tests, specs, or whatever
$ rvm install 1.9.2
$ rvm use 1.9.2
$ rvm gemset create rails3
$ rvm use [email protected]
$ rails new myapp
$ cd myapp
$ echo "rvm use [email protected]" >> .rvmrc
$ vi Gemfile   # add the following to your gemfile 
group :development, :test do
 gem 'sqlite3-ruby', :require => 'sqlite3'
 gem "rspec-rails", ">= 2.0.0.beta.22"
 gem "webrat"      # currently generated view specs require this
$ bundle install
$ rails generate rspec:install
$ rails generate scaffold note title:string content:text
$ rake db:migrate
$ rails server

Good resources

One Comment

  1. Brad
    Posted September 28, 2010 at 11:19 pm | Permalink

    This just in: Heroku now supports 1.9.2! So no need to use 1.8.7 anymore for Rails 3 if you’re a Heroku user…

    Here’s the heroku command for starting a project (i.e., heroku stack) that uses 1.9.2… It’s:

    heroku create -stack bamboo-mri-1.9.2

    or to migrate a current app to their new stack, it’s:

    heroku stack:migrate bamboo-mri-1.9.2

    This latter command would be if you are migrating a current app (from 1.8.7 for instance) to 1.9.2 …

    Hopefully Heroku support will update their link (in 2. above) soon, but the above does work now (and was communicated to me by someone in Heroku support).

One Trackback

  1. By Peer Pressure for Rails 3 - on September 25, 2010 at 7:39 am

    [...] HomeClassesCross TrainingContact UsBlog « SVG Scripting with JavaScript Part 1: Simple Circle Rails 3: getting started » [...]

Post a Comment

Your email is never shared. Required fields are marked *