Brian began developing applications for the Internet in 1995, and has continued to architect, design and develop Internet software for the last 11 years, including projects for IHG, IBM, Brighthouse, and Cox Target Media (Valpak).

Brian now works in Ruby on Rails full time as part of the team developing the two official web sites for Miley Cyrus.

June 2008


Date Validator for Rails

This week on a project I had the need to signal the user when they had entered an invalid date for a date field that wasn’t required. But I needed to show the error even if they entered a bunch of garbage into the field. Unfortunately in Rails, if you attempt to set a string into a Date field it doesn’t set at all, and so when the validator fires there is nothing to validate and since the field isn’t a required field, no error is displayed.

After searching the net extensively, I found this ruby class for adding a validates_dates function. It is very helpful and not only solved my problem, but also gives the users a few shortcuts for entering the date, such as the following examples.

+6days, +6d, +6, +2w, -6m, +1y

It also allows you to define, in the validation usage, a from and to range that the date should be within. For example, a person’s renewal date should not be before their created_at date, or limiting a date field to be beyond today.

validates_dates :birthday, :from => '1 Jan 1920', :to => Date.today, :allow_nil => true

The snippet is here.

YellowPages.com on Rails

RailsonWave.com summarizes the recent talk at RailsConf 2008 regarding YellowPages.com’s move from Java to Rails. They serve up 23 million visitors a month. The conversion resulted in 20,000 lines of Ruby code instead of 125,000 lines of Java code, and most importantly eased the difficulty they had in maintaining it. Once complete, and optimized their site is now faster than before. They also completed the rewrite in three months with four developers. You can read the entire write up at railsonwave.com.

RailsConf 2008 Overview

I wasn’t able to attend but for those of you like me, RubyInside has a great summary of the entire thing: The Mega RailsConf 2008 Round Up.

« Previous PageNext Page »


Close
E-mail It