Topic: Creating new Rails App, right version

When I run "rails appname" I create a new rails app as usual.  When I check the config/environment.rb file I can see that I've created a Rails 1.2.4 app, despite the fact that I've installed the Rails 2.0.1 gem.  Where do I change my reference to "rails" so that when I run the rails command I am creating a 2.0.1 app?

I'm on Ubuntu.

Thanks.

Last edited by mlanza (2007-12-23 12:06:09)

Re: Creating new Rails App, right version

environment.rb

RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION

Re: Creating new Rails App, right version

I understand how to make a Rails app a 2.0.* app.  But I am thinking that when I run

rails appname

that the files that rails creates for the resulting app should be the template files that Rails 2.0.1 provides, not the old templates from 1.2 Rails.  I am getting 1.2.4 Rails templates.

So, I am thinking that when I run "rails appname" I am somehow calling old rails not the latest rails.

My question is when I enter "rails appname" from the console, how does it know which version of the rails gem to run to generate the template application?

Re: Creating new Rails App, right version

Rails will always run the latest version you have installed. To specify earlier versions, you have to change the constant in config/environment.rb called RAILS_GEM_VERSION to whatever version you want, like ediestel recommended.

Re: Creating new Rails App, right version

I still think you're missing the problem.

If I run "script/generate scaffold Person" on a newly generated rails app, it generates views with the .rhtml extension.  The new views should be .html.erb.  The app itself is being generated from old rails.  I realize I can change the GEM reference in the environment.rb file to allow it to run the app with the new rails gem; however, the newly generated files are still old rails files.

Is my understanding not right?

Re: Creating new Rails App, right version

Scaffolding has been taken out of Rails 2.0, so no, the views shouldn't be .html.erb.

Re: Creating new Rails App, right version

In any case, I am able to run the script/generate scaffold on a new app.  If the app was created in 2.0.2, then I shouldn't be able to accomplish that.

I want to clarify...

When I run a rails command, I am not actually referencing any environment.rb file because there is none.  I am about to generate an environment.rb and a bunch of new files for my freshly created app.  When the app is created, it is clear that the rails command actually ran old rails, not 2.0.2.

When I run "rails" that command executes a script somewhere.  What script is that command executing and how do I change it?

Re: Creating new Rails App, right version

Actually I see that I am running rails from /usr/bin/rails script, the rails that was installed with ubuntu.  So I figured out that issue.  Where is the equivalent script that comes in the gem for generating rails apps?

Re: Creating new Rails App, right version

mlanza wrote:

Actually I see that I am running rails from /usr/bin/rails script, the rails that was installed with ubuntu.  So I figured out that issue.  Where is the equivalent script that comes in the gem for generating rails apps?

Erm... do rails -v and I think you'll find the gem overwrites /usr/bin/rails smile

Re: Creating new Rails App, right version

Actually after much difficulty I fixed it.

First, was running the rails that came with the Ubuntu distro not the gem.  Uninstalled rails with package manager (leaving gem intact).

Created script /usr/bin/rails from one I found on my host site.

That did the trick.  I was in fact, running the old rails as I suspected.  Now that the changes has been make "rails -v" reveals 2.0.2.

Thanks for the help.  I appreciate your effort!

Re: Creating new Rails App, right version

I understand that this post has long been resolved, but the original question remains:

Given the fact that I have a newer edition of Rails installed, is it possible for me to create an app with an earlier Rails version?

This question is relevant because when you create a rails app

$rails <app_name>

it will create an application with the code based on the most recent Rails version installed on your system. This means that even if you try and change the Rails version in environment.rb the code that makes up the application is still from the newer version. This will lead to incompatibilities due to the changing nature of Rails.

The simple answer is yes, it is possible to create a new Rails app based on an older version of Rails even if you have a newer version installed.

As an example, let's say I have Rails 2.2.2 installed on my system, but I want to create an app in Rails 2.0.2. (A good reason may be that my host has not yet upgraded to 2.2.2, or I'm following a tutorial or book that is written in 2.0.2)

You must also have the previous version of Rails (the one you want to create your application with - in this case 2.0.2) installed. Find out like this:

$ sudo gem list rails
rails (2.2.2)

which will tell you which versions of rails are installed on your system.

If the one you want isn't installed, install it like so:

$ sudo gem install rails --version 2.0.2 --include-dependencies --no-rdoc --no-ri

check it is now installed:
$sudo gem list rails
rails (2.2.2, 2.0.2)

Once it is installed you can then create a Rails app and specify what version you want to use:
syntax: 
$rails _x.x.x_ <appname>

example:
$rails _2.0.2_ app


A new app has been created with the 2.0.2 codebase, despite having 2.2.2 installed on the system as well.

Hope this helps someone out there, and goes in some way to answering the original question of this post.

Re: Creating new Rails App, right version

Hi guys, this is my first post on the railsforum. I just registered so that I could say thanks to pootsy for getting this question resolved. I wasted 25 minutes googling before I finally found the (simple) answer. Pootsy, thanks again.