Switching between different version of rails in same gem set - ruby-on-rails

I have installed two different version of rails in same gem set. When I do gem list rails it will show as follows:
**rails (3.0.11, 2.3.8)** // This means I have two rails
When I create new rails application it will take latest one, that means app should be created using rails new app_name not using rails app_name.
But I want to use rails 2.3.8 instead of 3.0.11. I know that using RVM helps in switching between different version of rails but they are installed in different gem set. Is there any possibility to switch between different rails version in same gem set?
Thank you.

The later version has higher precedence. You have to be explicit when create app by:
rails _3.0.11_ new my_app
OR
rails _2.3.8_ my_app

I'm assuming you are not using Bundler if you are trying to use 2.3.8, so check your config/enrvironment.rb file and change the RAILS_GEM_VERSION to '2.3.8'

Related

Can I use different version of rails for different projects directory in Windows?

Currently Rails 4.0.2 is installed in my Windows machine and I'm using it for several rails projects. But, I do want to use Rails 3.2.8 version for another project.
So, my question: Can I specify the version 3.2.8 on a single project and retain 4.0.2 in all the rest by ensuring all dependencies for 3.2.8 are installed?
Yes !
Install the rails 3.2.8 gem.
Then, you can specify which version of rails you want to use :
rails _3.2.18_ new mySuperSecretProject
In each project, you can use rails _xxx_ console, but it is easier do directly use the binstubs : bin/rails console
Yes you could do it as Intrepidd stated.
Another way to do this is by including a specific gem version in your application Gemfile and then do a bundle install. This will tell the application to use that particular version of rails over your system version
Rails can be installed as follows:
1) Specify the rails gem version in your project Gemfile
gem 'rails','3.2.8' OR gem 'rails', '4.0.2'
2) Try running bundle install. it will automatically install required rails version for you and will create a bundle unique for the project you are in.
3) For rails 4.0.2 project: if rails 3.2.8 is already installed, try running 'bundle update rails' to upgrade the current rails version and it will install all of its dependencies in the corresponding bundle.
If you want to run these projects in different ruby versions, then in Linux platforms RVM is the best option. But, in windows RVM will not work. A good option will be the Pik tool. Pik is a tool to manage multiple versions of ruby on Windows.
Please refer here for the same. Hope it helps :)

How can I generate older rails application when current version is 3.0.3

I have 2 different Rails Rubygems installed on my Linux OS [2.3.8 and 3.0.3], but the current active Rails version is 3.0.3. So is it possible to generate Rails app using 2.3.8 style generator:rails testapp not new one: rails new testapp?
You can tell Rails to use version 2.3.8 like this:
rails _2.3.8_ testapp
I'd recommend installing RVM and setting up different gemsets for each version of Rails. That way you can easily switch between Rails versions by just switching gemsets.
See here: How to use the Rails 2.3 app generator when I have Rails 3 installed?
Quoting Leonid Shevtsov:
The easiest way to do it was:
Create the directory for the project
Create a Gemfile there containing
gem "rails", "2.3.9"
gem "sqlite3-ruby", :require => "sqlite3"
Run "bundle install"
Run "bundle exec rails ." to create an app in the current path
You don't even need rvm to do this.
You could also use rvm.

creating a new rails project in rails 2.2.2 (while having rails3)

In my computer (linux - ubuntu) I have installed rails 2.2.2 and rails 3
Now i want to create a project in rails 2.2.2. (Like rails ). But it asks to enter the rails command as in rails 3 (like rails new )
when i type rails -v it shows the rails version as 3. But in my gem list it has both rails 2.2.2 and 3
how can i create a project in rails 2.2.2
thanks in advance
cheers
sameera
Generally speaking if you have two versions of ruby and rails installed the last one will be the "normal" one using "normal" commands like:
ruby
rails
gem
For all the other versions you can define (or have defined during installation) some aliases like:
ruby187
rails222
gem222
Another solution could be this
Or the best solution I recommend for working with multiple ruby and rails versions is RVM
You can do this. Create a rails project.
rails myproject
Go to your envirnonment file and modify to
RAILS_GEM_VERSION = '2.2.2' unless defined? RAILS_GEM_VERSION
EDIT
Yes , Sorry about that .This method may have worked in rails versions < 3. My Bad ! RVM the way to go.
Should do the trick. Also I recommend you update to atleast Rails 2.3.9, in case you don't want to start off with Rails 3.
There are 3 easiest ways how to manage it:
0) remove not used version of rails
1) rails is just simple command, so each time when you need to run special version of it you can specify full full path to it( or alias it one time)
2) if you strongly need to have different types/versions of ruby environments( and/or different versions of ruby gems such as rails), I recomend you to use rvm - it is the most easiest way to manage it.
When you want to specifically use one version of your installed version for a specific project use
rails _2.2.2_ (your project)

Multiple Rails versions for multiple projects

I'd like to use Rails 2.2.2 for one project and Rails 2.3.2 for another. Both are installed.
What is rails _2.2.2_ --version supposed to do? I've read that it makes 2.2.2 the working version -- that is, the version that will be used from that point on. But when I check rails --version, I get Rails 2.3.2. So, I also want to know what rails --version tells me; is it just the latest version of Rails that I have or is it the version that will be used for rakes?
I know about RVM. Is that the best way to use different versions of Rails on different projects?
Yes "rails --version" tells which is the latest version of rails. If you want to check different versions of rails installed in your machine you have to do "gem list" which gives the list of all the gems installed in your machine with their versions.For Ex:-
rack (1.0.0)
rails (2.3.4, 2.1.1)
rake (0.8.7)
Is that the best way to use different versions of Rails on different projects?
My point of view is that No it's not a good practise to use diiferent Rails version for the different projects. but sometime you used your old projects which is of an earlier version so you have no option but install that rails version. But while creating a new application you should used the latest stable rails version.
Just for record you can used different Rails version for different projects by mentioning Rails version in enviorment.rb For Ex:-
RAILS_GEM_VERSION = '2.1.1' unless defined? RAILS_GEM_VERSION
I would try RVM gemsets for this, because it's likely that you will need to keep separate sets of dependencies for each project as well as separate versions of Rails itself.
RVM seems generally a much tidier approach - using separate environments instead of a single pool of gems means that you can easily create or destroy environments without breaking others, and it reduces the risk of making a mistake when you specify the versions of dependencies.
In the Python world people use virtualenv to create completely separate environments for each of their projects, and I think that this is a good idea to copy.
In the config/environment.rb file look for RAILS_GEM_VERSION and set the value to the required version.
RAILS_GEM_VERSION = '2.2.2' unless defined? RAILS_GEM_VERSION
OR
RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
I would use Bundler: http://gembundler.com/
It's pretty easy to get used to, and has other benefits. It's by some of the Rails core members, and I believe will become the recommended solution soon after Rails 3.0.
To answer your original question, the underscore in your version number are used to specify a version when you create a new rails app. For example if you were to create a new rails app, rails would use the latest version installed in your system by default, but what if you wanted to use an older version installed on your system?
Here is the command...
rails 2.3.4 killerapp
You will need to have rails gem 2.3.4 installed on your system!
For that you can use rvm and gemsets to group your ruby/gems in convenient packages.
I hope this helps

How do I use an old version of Rails with Aptana RadRails?

I'm new to Rails development, and I'm trying to figure out how to use an older version of Rails with Apatana's RadRails IDE. I'm trying to help out a friend who has a site built on older version than the one that automatically gets downloaded by RadRails, and I'm pretty sure the two versions wouldn't be compatible (the site is using some pre 2.0 version, not sure of the exact number offhand).
Is there a way to tell RadRails to get and use a specific version of Rails? Or is there something I can do at the command line to change the installed version of Rails? I'm only vaguely familiar with the "gem" package system, but I'm assuming it would involve that.
Any help would be much appreciated!
Use the Rake task rails:freeze:gems in your rails project and give it the version you want to use. For example:
rake rails:freeze:gems VERSION=2.1.0
That will put the right version of Rails into vendor/rails, which is loaded by default if it exists.
If you don't want to freeze the gem into your project (using rake rails:freeze:gems), you can install the rails gem of the version you want to use:
gem install rails -v 2.0.2
and then specify the rails gem to use in your config/environment.rb:
RAILS_GEM_VERSION = '2.0.2'

Resources