开发者

Managing many Ruby on Rails applications of different versions

开发者 https://www.devze.com 2022-12-14 16:19 出处:网络
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

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 phi开发者_StackOverflow社区losophy! But I'm sure I'll grow to appreciate RoR.


As for Rails, What you can do is freezing your version, for example:

  1. Make sure to install the proper Rails version, suppose you want version 2.2.2 : gem install rails v=2.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.

0

精彩评论

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

关注公众号