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
Advertisements

2 thoughts on “Create new app with specific Rails version

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s