Forum: Ruby on Rails Switching the version of Rails that an app uses

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
RichardOnRails (Guest)
on 2008-11-22 01:23
(Received via mailing list)
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
http://kylecordes.com/2008/04/30/git-windows-go/
.  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:

=============
RAILS_GEM_VERSION is defined
RAILS_GEM_VERSION:
2.0.2
=============

That looks promising!!

D. = = = = = = = = = = = = = = = = = = = = = = = =
I pointed Firefox 3.0.4 at http://localhost:3000/payrolls and got a
Routing Error (because I hadn’t fleshed out the app yet) and got
Mongrel output that included the line:

K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/
actionpack-2.2.0/lib/action_controller/routing/
recognition_optimisation.rb:66:in [snip]

indicating that Rails 2.2.0 was being used, not 2.0.2 that I specified
nor 2.2.1 that Rails –v reported.
RichardOnRails (Guest)
on 2008-11-22 05:54
(Received via mailing list)
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

On Nov 21, 6:23 pm, RichardOnRails
Web R. (Guest)
on 2008-11-22 09:03
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
Bill W. (Guest)
on 2008-11-22 17:40
(Received via mailing list)
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
RichardOnRails (Guest)
on 2008-11-22 22:06
(Received via mailing list)
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


On Nov 22, 2:03 am, Web R. <removed_email_address@domain.invalid>
RichardOnRails (Guest)
on 2008-11-22 22:20
(Received via mailing list)
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
Frederick C. (Guest)
on 2008-11-22 22:25
(Received via mailing list)
On Nov 22, 8:05 pm, RichardOnRails
<removed_email_address@domain.invalid> wrote:
> 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...)

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

Fred
Frederick C. (Guest)
on 2008-11-22 22:27
(Received via mailing list)
On Nov 22, 3:39 pm, "Bill W." <removed_email_address@domain.invalid> wrote:

> 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.
>
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
Bill W. (Guest)
on 2008-11-22 23:36
(Received via mailing list)
Hi Fred,

Frederick C. wrote:
On Nov 22, 3:39 pm, "Bill W." <removed_email_address@domain.invalid> 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
Frederick C. (Guest)
on 2008-11-22 23:45
(Received via mailing list)
On Nov 22, 9:36 pm, "Bill W." <removed_email_address@domain.invalid> wrote:

>
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
RichardOnRails (Guest)
on 2008-11-23 02:38
(Received via mailing list)
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:
============================
uninitialized constant
CvsItemsController::BUG_BUG_BUG_BUG_BUG_BUG_BUG_BUG_RLM
RAILS_ROOT: K:/_Projects/Ruby/_Rails_Apps/PayrollSys
Application Trace | Framework Trace | Full Trace
K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/gems/1.8/gems/
activesupport-2.2.0/lib/active_support/dependencies.rb:102:in
`const_missing'
app/controllers/cvs_items_controller.rb:96:in
`get_csv_filenames_attributes'
app/controllers/cvs_items_controller.rb:9:in `index'
===========================
suggest that my specification of Ruby 2.0.2 was not honored; Version
2.0.0 gems are continuing to be run.

I posted the relevant code on http://www.pastie.org/321639 in case you
want to see if I’ve done anything stupid.  The files include:
- config/environment.rb
- app/controllers/cvs_items_controller.rb (bug in last method)
- ActionController Exception

> (see http://github.com/rails/rails/tree/master/railties..... .)
I'll check out the link now.  Goodness knows,  I can always use more
Rails education.

Best wishes,
Richard


On Nov 22, 3:24 pm, Frederick C. <removed_email_address@domain.invalid>
RichardOnRails (Guest)
on 2008-11-23 02:51
(Received via mailing list)
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

On Nov 22, 4:45 pm, Frederick C. <removed_email_address@domain.invalid>
Rick (Guest)
on 2008-11-23 11:19
(Received via mailing list)
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

On Nov 22, 2:50 pm, RichardOnRails
Frederick C. (Guest)
on 2008-11-23 13:05
(Received via mailing list)
On Nov 23, 12:50 am, RichardOnRails
<removed_email_address@domain.invalid> wrote:
> 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.
>
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
RichardOnRails (Guest)
on 2008-11-25 06:05
(Received via mailing list)
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
RichardOnRails (Guest)
on 2008-11-25 06:20
(Received via mailing list)
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

On Nov 23, 6:04 am, Frederick C. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.