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'
Related
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 :)
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
I'm learning Ruby on Rails with the AWDR book and have had to be specific about which version of Rails and Ruby that I am running on my local machine. I have just discovered that I need to roll back from ruby 1.8.7 to ruby 1.8.6 here. I also needed to roll back Rails to support the scaffold method so I could start the tutorial easily.
My question is: When I start contracting, developing and deploying projects in the real world, how am I going to manage all these different versions?
It looks to me like Rail's low tolerance for legacy code negates its ease of use philosophy! But I'm sure I'll grow to appreciate RoR.
As for Rails, What you can do is freezing your version, for example:
Make sure to install the proper Rails version, suppose you want version 2.2.2 : gem install rails v=2.2.2
Freeze and pack Rails with the project itself : rake rails:freeze:edge RELEASE=2.2.2
Now you will find Rails packed inside the vendor folder of your project, so you don't have to install Rails on the deploying machine.
And for Ruby, I like Ruby Version Manager(RVM), the easiest way to manage Ruby versions.
RubyGems is Ruby's package manager. You can install as many versions of gems (packages) as you want. You can install the latest by running sudo gem install rails (at the moment it will install 2.3.5). If you need 2.2.2, specify that with the -v or --version option: sudo gem install rails --version 2.2.2. Rails also installs a binary (yes, I know it's not really a binary file), rails, which generates a project. Because you have several versions of the gem, you need to control which binary gets called. When you install the rails gem, RubyGems puts a file in it's bin/ dir, which is a "link" to the real rails binary. That is the one you "call" when you say rails on the command line. However, all of the rubygems "link" binaries accept a parameter of it's own, which is what version you want to use. You would use the 2.2.2 rails binary like this:
rails _2.2.2_ my_project
I think the default is to use the most recent version, so if you want to use the most recent version, do this:
rails myproject
However, I see that you use 2.2.2 to get access to the scaffold method. I would strongly suggest you not to use that method, there's a reason for removing it. The scaffold method hides code, and makes customization hard. Instead, use the scaffold generator:
./script/generate scaffold --help
Good luck on your future rails adventures!
The latest version of Agile Web is written for 2.2.2 I believe. For this basic app they walk you through I'm very certain it should work with 2.3.x
The answer to the question for how you keep up is that you update your apps as needed and read the api and Changleogs to find out what has changed and fix the stuff that upgrades break. A great way to help with this is having a good test suite with good test coverage.
I have an older Rails app that I need to run. But I have the latest version of Rails.
When I try to run this older app it says:
Missing the Rails 1.99.0 gem. Please
gem install -v=1.99.0 rails
But when I run the command: gem install -v=1.99.0 rails
ERROR: could not find gem rails
locally or in a repository
Not sure what to do next. Could someone help me understand what's happening here?
And my second question, related to this problem is: It seems silly that I need to revert to an older version of Rails just to run this one legacy app - there must be a better way of doing this?
AFAIK, v1.99.0 is sort of a v2.0 prerelease, so you could try installing v2.0.x, changing the RAILS_GEM_VERSION in config/environment.rb and runing rake rails:update.
If you think about it, it's not as silly as it might seem at first. You make an app using a fast evolving web framework as RoR. Your choices are: continue developing your app at aproximately the same pace the framework is evolving, or freeze the rails gem (and evertything else your app depends on, like gems, plugins) into your app in order to make it less fragile to expecting gem updates.
Regarding the second question: yes it is silly. Fortunately the Rails team spotted that silliness and at some point they gave us the ability to "freeze" the versions of Rails libraries required by an application (and also specific gem versions) into the vendor directory.
To freeze your version of Rails:
rake rails:freeze:gems
There's a good blog post from a while back describing this.
Unless you install and deploy RVM, your installation will roll back your system rails installation, which will impact your other projects. If you want to manually administrate your development environment this way, you can uninstall rails first, and then install the desired version of rails for the current project.
But try to install your rails gem instead with this syntax:
sudo gem install rails -v 1.99.0
I am currently using Rails 2.1.0 and want to upgrade to Rails 2.1.1. After issuing the following command
gem update rails
I suppose that I need to change this line
RAILS_GEM_VERSION = '2.1.0' unless defined? RAILS_GEM_VERSION
in environment.rb
What other actions should I take to ensure that my application is using the latest version? Are there some other files that need an update?
You'll also need to go into your application directory and run the following command:
rake rails:update
Then run your tests and make sure everything works.
As far as I know, that right there defines what version of rails your application as a whole will use. I know for a project I'm in right now I had to override that to 2.1.1 to work on my VM because I had installed the latest, and had not specified the 2.1.0 as required by the project.
The biggest thing you have to watch out for is plugins and extensions that may override this setting, as well as incompatibility that will likely arise from changing versions.
Also there are some known issues with 2.1.1, unless there is a feature you absolutely need now, you may want to wait.