开发者

Multiple Rails versions for multiple projects

开发者 https://www.devze.com 2022-12-27 05:49 出处:网络
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 -- th

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号