ActionView::Helpers::DateHelper

date_select

Description

date_select(object_name, method, options = {})


Returns a set of select tags (one for year, month, and day) pre-selected for accessing a specified date-based attribute (identified by method) on an object assigned to the template (identified by object). It’s possible to tailor the selects through the options hash, which accepts all the keys that each of the individual select builders do (like :use_month_numbers for select_month) as well as a range of discard options. The discard options are :discard_year, :discard_month and :discard_day. Set to true, they’ll drop the respective select. Discarding the month select will also automatically discard the day select. It’s also possible to explicitly set the order of the tags using the :order option with an array of symbols :year, :month and :day in the desired order. Symbols may be omitted and the respective select is not included.

Passing :disabled => true as part of the options will make elements inaccessible for change.

NOTE: Discarded selects will default to 1. So if no month select is available, January will be assumed.

Examples:
  1. date_select("post", "written_on")
  2. date_select("post", "written_on", :start_year => 1995)
  3. date_select("post", "written_on", :start_year => 1995, :use_month_numbers => true,
  4. :discard_day => true, :include_blank => true)
  5. date_select("post", "written_on", :order => [:day, :month, :year])
  6. date_select("user", "birthday", :order => [:month, :day])

The selects are prepared for multi-parameter assignment to an Active Record object.

  1. date_select("post", "written_on", :default => "2007-06-24")

User Contributed Notes add

No comments