Rails version 1.2.5 and Capistrano 2.1

October 15th, 2007

If you blinked you would have missed version 1.2.4. Rails version 1.2.5 has been released. For the most part, it is a security release to fix a JSON problem. If you aren’t using JSON, then it’s optional but never a bad idea.

If you didn’t upgrade to version 1.2.4 already, don’t be alarmed when gem install rails --include-dependencies downloads version 1.2.5 now.

If you want to upgrade to 1.2.5, you can follow the same steps as I outlined previously for 1.2.4.

And Capistrano 2.1 has been released.

Capistrano is a tool for automating tasks on remote servers, especially those running Ruby on Rails applications. It lets system administrators execute commands and roll back changes in parallel across multiple machines.

Rails version 1.2.4

October 11th, 2007

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.

She’s Geeky

October 4th, 2007

She’s Geeky

She’s Geeky will be an (un)conference in Mountain View, CA on October 22-23. Tickets are $175.

It is designed to provide women who self-identify as geeky and who are engaged in various technology-focused disciplines with a gathering space in which they can exchange skills and discuss ideas and form community across and within disciplines.

What’s an “(un)conference”? There will not be an organized agenda, instead the attendees will decide on the content. There is a Wiki page with proposed topics.

Rails 2.0 Preview Release

October 2nd, 2007

Rails 2.0 PR

The Rails 2.0 Preview Release is out. David Heinemeier Hansson provides an overview of some of the new features. There may be several preview releases before the final release. I’m sure there will be bug fixes—but DHH said in his RailsConf Europe keynote that 37signals has been running many sites (including Basecamp) on most of the Rails 2.0 code for several months, so it ought to be pretty solid by now. If I had to guess, I’d say we are 3-4 weeks away from a final release.

Before the final release, the Rails core team have also promised to release version 1.2.4. The update to Rails 1.0 will likely include minor bug fixes, however it’s primary purpose will be to provide complete deprecation warnings. So the process will be: upgrade to 1.2.4, try everything, watch the log files for deprecation warnings, fix any incompatible code, then upgrade to 2.0. Don’t be surprised if 1.2.4 is released only a week before 2.0.

The best way to safely try out the preview release is to download it into the vendor directory of a Rails project. (You will need Subversion installed. If you are on a Mac, this guide can help you install it.) Using a command line, navigate into the root of the project and type:

1
rake rails:freeze:edge TAG=rel_2-0-0_PR

Once the download is complete, that Rails project (and only that project) will be running on the preview release. Type rake rails:unfreeze if you want to go back to your regularly installed Rails version. Advanced users can opt to install the gem version of the preview release instead.

UPDATE: If you are on Rails 1.2.3, you’ll need to run the “freezing” twice. The first time will not download the new ActiveResource pieces (Rails 1.2.3 doesn’t know about them) and you’ll get errors when you try to start the server. When you run it the second time, Rails will know that it should have ActiveResource and will retrieve it for you.

RailsConf Europe

September 26th, 2007

RailsConf Europe took place last week in Berlin. Below are the links to speaker notes and reviews that I’ve collected.

Speaker Notes

Official Slide Summary

Reviews and Commentary

Let me know if you know of others and I’ll post them too.

php|works 2007

September 26th, 2007

I’ve been lax about blogging over the last few weeks. September is always a busy month. Everything that was put on hold during August vacations suddenly shifts into high gear. My back log of blog-worthy posts is intimidating, so I’ve decided to handle it expeditiously and keep posts short and sweet until I’m caught back up.

php|works 2007 was two weeks ago in Atlanta. Below are some of the session notes and online reviews I’ve collected.

Session Notes

Reviews and Commentary

Let me know if you find more and I’ll add them to the list.

Music for Coders: September 15

September 15th, 2007

New and Notable This Week

  • Calvin Harris: I Created Disco
    I’m a fan of LCD Soundsystem, Datarock and HBO’s “The Flight of the Conchords”. How could I not love this too? I think this music would fall under the label “electroclash”. To me, it sounds like David Bowie, Talking Heads, and Kraftwerk all mashed together.
  • Hot Hot Heat: Happiness LTD.
    This is what bubblegum indie-rock sounds like. It’s not very filling, but if you like The Killers, Franz Ferdinand and The Bravery it might tide you over until the next meal.
  • Black Lips: Good Bad Not Evil
    Delightfully-out-of-tune garage and surf punk. They remind me of The Creation, The Sonics and The Pretty Things. I know those names are nowhere near the mainstream, so if you don’t already know that you like garage it’s probably not for you.
  • Rogue Wave: Asleep at Heaven’s Gate
    A good alt rock band that reminds you of dozens of other alt rock bands. That’s both a reason to like them and a reason to skip them.
  • Shout Out Louds: Our Ill Wills
    The Cure meets The Killers. That forumla is wearing out.
  • 50 Cent: Curtis
    Not groundbreaking but there is some good stuff here. I like the guest appearances: they show good taste and they add much needed contrast to his gravelly voice (and keep everything from sounding like “In da Club”). I probably couldn’t code to it though—it commands too much of my attention.
  • Ben Harper & The Innocent Criminals: Lifeline
    Soul, blues, gospel, country and even folk influences show up on Ben Harper’s latest.
  • Various Artists: Across the Universe
    Terrible Beatles covers. Even the songs with Bono are bad.

Rotating Rails Log Files

September 10th, 2007

Logrotate

One of the chores I dislike most is cleaning up and clearing out the log files in my Rails applications. On some of my higher profile sites, I get a lot of spiders probing my applications for security holes. They don’t succeed (knock on wood) but they do fill up my log files with errors.

I finally decided to get smart and get lazy (the two best traits a programmer can have), and I set up automatic log rotation on all of my Rails applications. The idea behind log rotation is simple: make a back up of the current log file, continue logging into a new or cleared log file, and discard log files that are older than a certain date.

Your webserver probably already rotates its own log files. For Apache, they are probably located in /etc/httpd/logs and they are probably rotated weekly. These logs store everything Apache does. Simple webserver stats and traffic analysis tools make use of these log files to show who visits a site when and what pages are viewed.

While it is possible to configure your Rails application to log to your Apache log files, I do not think it is a good practice. It’s much better to give each Rails application its own log file—it will be easier to find important Rails errors, it will keep your Apache logs cleaner and Rails is set up to keep its own logs by default. Fortunately, on a Linux server the built-in logrotate program will make the process super-easy. After the jump, I’ll walk you through the steps to get it set up.

Read the rest of this entry »

Music for Coders: September 8

September 8th, 2007

I already raved about the newest Spoon album. They are one of my favorite bands and it’s one of the best albums of the year.

Now you have to check out this video for “Don’t You Evah” which features the Keepon robot. The song was already catchy, but the video will put it in your head for weeks! The video was a collaboration between Spoon (several members even make cameos) and Keepon to promote WIRED NextFest which is next weekend, Sept. 14-16, in Los Angeles. Spoon will be playing a kick-off concert on Monday, September 10 to benefit Creative Commons and the Keepon robot is scheduled to join them. (I would have thought he’s too big of a rock star by now… I’m glad to see he’s still humble.)

I love it when creatives and geeks work together. Left brain meets right brain—the way it should be.

On a sad note, opera lovers worldwide will miss Luciano Pavarotti. I’m an opera fan but I never got to see the great Pavarotti. iTunes: “Luciano Pavarotti – The Best”

New and Notable This Week

  • Manu Chao: La Radiolina
    Manu Chao is immensely popular in Europe and Latin America, sings in seven languages, and writes rock/folk/world music with a leftist/political/protest angle that incorporate at least as many musical styles. His music has always been fractured and his new album features 21 songs, many of them under 2 minutes, but he moves between styles, languages and genres so deftly that you won’t notice the shift. He has appeared at numerous festivals and opened for bands like Rage Against the Machine, yet his U.S. success has been minimal. To me, this album feels like an attempt to be more mainstream and ends up being good but not as satifsying as his other albums. The earliest tracks are best, especially “Tristeza Maleza”.
  • Björk: Family Tree
    An interesting approach to a greatest hits album. Björk selected her favorite songs and packaged them together with art and commentary so that it stands on its own as more than just a greatest hits. iTunes says that a fan selected greatest hits should have come out on the same day but I can’t find it.
  • Just Jack: Overtones
    U.K. rap that’s not bad, but not great either. His technique and style is not quite as original as The Streets, but his use of funk and soul elements that remind me of early Thicke or Jamiroquai makes up for it.

Post-Vacation Link Dump

September 4th, 2007

Here’s some of the exciting things I didn’t blog about while I was on vacation last week.