O'Reilly logo

Learning Rails: Live Edition by Edd Dumbill, Simon St. Laurent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

DateHelper

The DateHelper class contains two kinds of helper methods. There’s a small set of methods for expressing times in somewhat more human-friendly forms:

distance_of_time_in_words

Takes two time values and expresses how far apart they are in rough word descriptions rather than precise time notation—e.g., “2 days,” or “about 1 month,” or “less than a minute.”

distance_of_time_in_words_to_now or time_ago_in_words

Like distance_of_time_in_words, but with the to_time always set to now.

Most of DateHelper’s methods, though, create form fields for specifying times and dates. They’re kind of clunky, but they may be useful for when you’re getting started or when you feel like overriding them. Three of them are bound to particular objects of type :date, :time, or type :datetime:

date_select

The date_select method creates drop-down year, month, and day select fields bound to a particular ActiveRecord object of type :date.

datetime_select

The datetime_select method creates drop-down year, month, day, hour, minute, and second select fields bound to a particular ActiveRecord object of type :datetime.

time_select

The time_select method creates drop-down hour, minute, and second select fields bound to a particular ActiveRecord object of type :time.

The rest of DateHelper’s methods create HTML form fields, but aren’t bound to any particular ActiveRecord object:

select_date

The select_date method creates drop-down year, month, and day select fields.

select_datetime

The select_datetime method creates drop-down ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required