Switching the version of Rails that an app uses

Hi All,

I’ve got a few versions or Rails installed and I'd like to run an App I’m developing with various versions of Rails. I heard of two ways to switch the version of Rails that an app uses:

1. Use GitHub as described by Getting Started with Git and GitHub on Windows – Kyle Cordes . But that requires using Bash in a Command Window and more steps than I want to go through.

2. Alter environment.rb with one line to specify the desired version. That sounds like my kind of solution, except I can’t make it work.

My problem is that when I specify one of my installed versions, the Mongrel trace informs me that my specified Rails version is not being used, nor is the version that “rails –v” reports. Is there an easy way to get this mechanism working? Following are the gory details.

Thanks in Advance, Richard

A. = = = = = = = = = = = = = = = = = = = = = = = = Environment:

I’m running WinXP-Pro/SP3 with all the Windows updates, plus Ruby & Rails software as indicated below:

K:\>ruby -v ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]

K:\>rails -v Rails 2.2.1

K:\>gem list rails -l

*** LOCAL GEMS ***

rails (2.2.1, 2.2.0, 2.1.2, 2.0.2, 1.1.6, 1.1.4) rails-app-installer (0.2.0)

B. = = = = = = = = = = = = = = = = = = = = = = = = I modified config\environment.rb by commenting out “RAILS_GEM_VERSION = '2.2.0' unless defined? RAILS_GEM_VERSION” and followed it with the following 6 lines:

RAILS_GEM_VERSION = '2.0.2' # RLM puts "\n=============" # RLM puts "RAILS_GEM_VERSION is defined" if defined? RAILS_GEM_VERSION # RLM puts "RAILS_GEM_VERSION:" # RLM puts "#{RAILS_GEM_VERSION}" # RLM puts "=============\n\n" # RLM

C. = = = = = = = = = = = = = = = = = = = = = = = = I started Mongrel 1.1.4 and got, as expected, in the Command Window from which it was launched:

Hi All,

I should add that I don't have VendorRails installed. All I see under the vendor folder is a plugins folder, which is empty.

Best wishes, Richard

Hi,

Your problem is solved very easily.

Install Netbeans 6.5 today. It comes with an exclusive " FIRST TIME FEATURE " added in this new version.

It helps you choose the rails framework at the time of creating project. like Rails 1.2, 2.0.2, 2.1.2, 2.2.2 etc..

This was the most outstanding request and finally it has landed.

Hope this helps

Hi Richard,

RichardOnRails wrote:

I’ve got a few versions or Rails installed and I'd like to run an App I’m developing with various versions of Rails. I heard of two ways to switch the version of Rails that an app uses:

Given that you're working on Windows, the easiest way to accomplish your goal is to set up multiple versions of InstantRails. You can install the appropriate version of gems in each. Just copy your app into whichever copy of (Instant) Rails you're interested in. The problem with specifying different version of Rails prior to v2.0 has been the inability to specify the versions of the _other_ gems your app needs. Instant Rails gets you around that very nicely.

HTH, Bill

Hi again,

Wow, that's pretty neat. Of course, it's not quite as nice that I thought Rails offered with the line in config/environment.rb, namely overriding "RAILS_GEM_VERSION = '2.2.0' unless defined? RAILS_GEM_VERSION" somehow.

I'm going to hold out for a little while to see if someone can tell me why my attempt is working.

Thanks for your suggestion, Richard

Hi Bill,

Thanks for your response.

The problem with specifying different version of Rails prior to v2.0 ...

Interesting. But that sounds like what I was trying should have worked because I was trying to switch from 2.2.x to 2.0.2. Does the fact that I've got 1.x RubyGems installed impact what I was trying to do? Perhaps deleting them would have a salutary effect. I like having the 1.x around so I test my app on older version and authoritatively tell them about upgrading.

What do you think?

Best wishes, Richard

Hi again,

Wow, that's pretty neat. Of course, it's not quite as nice that I thought Rails offered with the line in config/environment.rb, namely overriding "RAILS_GEM_VERSION = '2.2.0' unless defined? RAILS_GEM_VERSION" somehow.

I'm going to hold out for a little while to see if someone can tell me why my attempt is working.

First of rails -v is always going to report the latest version of rails installed on your system. If you want to run another version of it you can do rails _2.1.2_ for example.

Secondly the trick here is that rails has to play a slightly dirty trick with RAILS_GEM_VERSION: it actually loads environment.rb and pulls it apart with a regular expression to find what you've set it to (see http://github.com/rails/rails/tree/master/railties%2Fenvironments%2Fboot.rb)

It's possible you've confused it with extra statements in environment.rb

Fred

You've always (or at least for a very long time) been able to require particular versions of gems. That functionality is part of rubygems itself.

Fred

Hi Fred,

Frederick Cheung wrote:

> The problem with specifying different version of Rails prior to > v2.0 has been the inability to specify the versions of the > _other_ gems your app needs. Instant Rails gets you around > that very nicely. > You've always (or at least for a very long time) been able to require particular versions of gems. That functionality is part of rubygems itself.

I'd definitely appreciate a link or two to how to make that work. That is, I've never figured out how to specify the 'whole package' of gems that should be pulled into play for a specific app. And then again there's the whole "is this plugin we're using 2.x compatible? thing. I've got three apps that are running on Rails 1.2.3, 2.0.2, and 2.1 respectively. It's been a lot easier to set up three distinct IR installs and work on each app in the one that contains what it needs. It also debugging easy when I recently migrated a 1.2.6 app to 2.1. But if there's an easy way to do the same thing with one install of Ruby, I'd definitely like to know about it.

Best regards, Bill

well plugins are a slightly different issue - you just have the appropriate version in vendor/plugins.

If you have a really wide range of rails apps you could end up with problems where the newer stuff needs a recent version of rubygems but the older versions of rails use require_gem which was deprecated and then removed. That aside take a look at http://www.rubygems.org/read/chapter/4#page71 (with the exception that require_gem has been replaced by gem)

Fred

Hi Fred,

Thanks for chiming in.

I changed config/environment.rb back to the original code, with one change: RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION in order to run my first Rails 2 version.

I also introduced the line:     BUG_BUG_BUG_BUG_BUG_BUG_BUG_BUG_RLM in my mal-named controllers/cvs_items_controller.rb in order to force some diagnostics in the Firefox 3.0.4 tab running my rails app.

The diagnostics:

Hi again, Fred,

I just started reading RubyGems Manuals using the URL you provided. That's stuff I should have learned a long time ago. Thanks for showing me how to get up to speed on RubyGems.

Thanks a lot for post that URL.

Best wishes, Richard

Hello Richard,

I'm voting that you should, when convenient, take a look at the NetBeans IDE. It does have a startup cost - installation is easy but it's a feature rich tool with lots of buttons to learn how to push. It does support multiple RoR environments and each Rails app can be fairly easily toggled between env.

Also, I looked at your controller code and I think you might have a problem with the value for csv_data_dir. I'm not sure where the relative path stuff (../../) ends up pointing in the InterWeb world. I'd go for csv_data_dir = RAILS_ROOT + "/public/data/csv".

Rick

No problem. Just to sanity check, you have been restarting mongrel whenever you edit environment.rb ? and you're sure that the content viewable at localhost:3000 is being served by that mongrel ?

Fred

Hi Rick,

when convenient, take a look at the NetBeans IDE

I definitely will as soon as I'm done with this payroll project. I presently use ScitTE because IMHO it's excellent for Ruby. But I can't use it effectively for Rails. I looked at Aptana a little, but on my system the startup is too slow to suit me.

csv_data_dir = RAILS_ROOT + "/public/data/csv"

You're absolutely right on your initial thought: My code doesn't return anything from the .csv files. I posted this issue on another thread express certainty that your suggestion is the correct solution.

I'm in the last stages of correction a typo when I generated a model in this app: I used a transposition of .csv, viz. .cvs. Being pigheaded, I decided to correct the app by programatically translating all /[Cc]vs/ instances in file names and file content to '\1sv". On the final step, I encountered a permissions problem in changing filenames. When I overcome that, I'll get back to the file access issue and then the features my client (my son) wants for this app.

Thanks for your extended interest and knowledgeable responses.

Best wishes, Richard

Hi Fred,

Thanks for giving further thought to my humble problem. Especially for the following:

you have been restarting mongrel whenever you edit environment.rb ?

No, I had not been restarting Mongrel immediately upon making a change to the config/environment.rb. I was blindly following the guidance that in development mode, all the changes to the app are picked when refreshing the web-page. But I certainly restarted Mongrel after I made a bunch of changes to the app, so that my revised environment code would have been picked up then. (I left my environment changes in place even though they seemed not to work.)

that the content viewable at localhost:3000 is being served by that mongrel ?

Yes. When I first address my browser to localhost:3000, my current app comes up and my logger.info stuff appears in the Command Window (under Microsoft WindowsXP-Pro/SP3) in which Mongrel is executing.

Best wishes, Richard