Rails version 1.2.4
As foreshadowed last week, Rails version 1.2.4 has been released. It’s mostly made up of security fixes and deprecation notices that will help you prepare for Rails 2.0.
Steps to Upgrade
Install Rails 1.2.4
Install the Rails 1.2.4 gem on your development server. You could install it by freezing a version into your vendor directory (like I recommended for Rails 2.0) but honestly, this release is minor and I recommend you simply upgrade the gem instead.
1 2 3 | gem install rails --include-dependencies #(or sudo gem install rails --include-dependencies) |
You’ll end up with both your old Rails version and version 1.2.4 as gems.
1 2 | # display all installed gems with: gem list --local |
You have a few choices on what to do with the old versions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # Option 1: uninstall all gems which have a newer version # (generally the best option after you are ready to commit to 1.2.4) gem cleanup #You can preview what cleanup will do with: gem cleanup --dryrun # Option 2: uninstall only the old Rails version # (use if you need to keep old versions of other gems around) # list the gems if you think you have different versions gem uninstall rails --version 1.2.3 gem uninstall actionwebservice --version 1.2.3 gem uninstall activerecord --version 1.15.3 gem uninstall actionmailer --version 1.3.3 gem uninstall actionpack --version 1.13.3 gem uninstall activesupport --version 1.4.2 # Option 3: uninstall the new Rails version # (only if something did not work out and # you need to revert to your old version) gem uninstall rails --verison 1.2.4 |
Track Down Deprecated Code
There are three ways that you can track down and update your deprecated code. I recommend doing as many of them as you can.
1. Run your application’s tests to see the deprecation warnings.
2. Click through your application by hand and watch the development log for the errors.
3. Save this code by Mislav Marohnić as “r2check.rb” and run it from the root of your application. It will scan through your application files searching for matches to regular expressions corresponding to deprecated code. (You won’t need to explicitly specify the location of your application—it will assume it is the current directory.)
For example:
1 2 3 | cd /path/to/your_rails_app ruby /path/to/r2check.rb |
Watch Out for Previously Deprecated Code
You’ll also want to make sure you’ve taken care of all previous deprecations. I’ve listed a few key ones below.
- @params, @sessions, @cookies, @flash, @request, @response, @headers, @env, and @template have all been deprecated in favor of simply using params, sessions, cookies, etc. without the @ prefix. (It’s a method call that returns an instance variable instead of an instance variable directly.)
- @content_for_layout has been deprecated. Use yield instead.
- Forms and links performing POST operations should use :method => :post instead of :post => true
- start_form_tag and end_form_tag are outdated. Use form_tag() do {...} or form_for() do {...} instead.
- render_partial has become render(:partial => 'something')
- find_all and find_first have become find(:all) and find(:first)
Install Pagination Plug-in
Pagination will be moving to a plug-in. If you have been using pagination anywhere in your application, you will want to install the plug-in for either ClassicPagination or change your code to use WillPaginate. (Both plug-ins can co-exist too if you want to start with ClassicPagination and move to WillPaginate over time.)
1 2 3 | # Note: you'll need to have Subversion installed ruby script/plugin install svn://errtheblog.com/svn/plugins/classic_pagination ruby script/plugin install svn://errtheblog.com/svn/plugins/will_paginate |
And then you’ll be in a great position to upgrade to Rails 2.0 once the final release comes out later this month!
UPDATE: I forgot to explicitly provide the final steps. Once you have the upgrade installed, go into your Rails application. Open up config/environment.rb and update the RAILS_GEM_VERSION to ’1.2.4′ or ’1.2.5′ (most likely on line #8). Save and close the file. Then from a command line from the root of your Rails application, run rake rails:update:configs. (First making backup of that directory is always the safest choice.) That will make sure your configuration files (like boot.rb) get updated with the latest code too.

October 11th, 2007 at 5:39 pm
You may also ActiveSupport::Deprecation.behavior = lambda { |message| raise message } to immediately raise an exception on deprecations.
December 9th, 2007 at 5:55 am
I tried this “sudo gem install rails –include-dependencies” but it updates Rails to version 2.0.1 not 1.2.4
What I really wanted was 1.2.6 to match what’s on my server. Is it possible to specify a version during the update?
I tried “sudo gem install rails –include-dependencies –version 1.2.6″
but it returns an error
ERROR: While executing gem … (OpenURI::HTTPError)
404 Not Found
December 9th, 2007 at 5:56 am
Okay worked it out
sudo gem install rails –include-dependencies -v 1.2.6