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 ...

Get Learning Rails: Live Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.