views:

133

answers:

3

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 philosophy! But I'm sure I'll grow to appreciate RoR.

+2  A: 

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.

railsninja
Helpful answer. But would that be possible? If I am contracted to work on an older version I must be able to run it. What if the client doesn't want me to upgrade it? Your solution does sound ideal, however.
Rimian
If you need to run the older versions of gems, specify them and their version in environment.rb, then freeze rails and gems into your vendor directory as suggested by @khelll.
railsninja
+3  A: 

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.

khelll
Darn it, now I have to learn more to understand your answer! Thanks :)
Rimian
Which part you don't understand?
khelll
I'm not up to speed on what gem and rake are exactly. I'll learn it soon enough I guess. If I packaged rails inside my projects, wouldn't I have a massive amount of code to manage after a dozen projects or so?
Rimian
gem is a code packaging code for ruby like jar for java. Rake is like linux make, executes tasks to be done. As for packing rails, no you wouldn't.
khelll
Thanks for the help!
Rimian
+1  A: 

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!

dvyjones
Yes, I see scaffold is depreciated. It's in the AWDR book. Once I go through the book I will discard it from my skillset :)Thanks!
Rimian