25 February 2010 ~ 2 Comments

Create new app with specific Rails version

I recently installed Rails 3 beta release but I needed to create new app with the 2.3.5. version. I was searching for a way to do that and I found this

  rails _2.3.5_ appname

Unfortunately this will produce an error similar to this

  /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:827:in `report_activate_error': RubyGem version error: railties(3.0.0.beta not = 2.3.5) (Gem::LoadError)
	from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:261:in `activate'
	from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:68:in `gem'
	from /usr/local/bin/rails3:18

To fix this first run

  which rails

and you will get a path to your rails executable, in my case this is /usr/local/bin/rails.

Then copy rails to rails3.

  sudo cp /usr/local/bin/rails /usr/local/bin/rails3

Then open this file in your text editor (TextMate in my case).

  mate /usr/local/bin/rails

and replace two last lines so that your file now looks like

  require 'rubygems'

  version = ">= 0"

  if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
    version = $1
    ARGV.shift
  end

  gem 'rails', version
  load 'rails'

Thats it, now you can create your app with specific Rails version with

  rails _2.3.5_ appname
Tags: , ,

2 Responses to “Create new app with specific Rails version”

  1. Tomislav Car 27 February 2010 at 2:45 am Permalink

    Why resolve to editing the “rails” file, why not just create different symlinks for different rails versions, so you have executables called

    rails2.3.5

    rails3

  2. vlado 27 February 2010 at 8:36 am Permalink

    I will leave mine like it is for now cause it is working fine, but I agree with you Tomislav, symlinks are much better approach.


Leave a Reply