Check for nil in Rails 3.0
(cherry picked from commit ccfcd6497f8ee093408c297023141b665d08459d)