date_select

  • :use_month_numbers – Set to true if you want to use month numbers rather than month names (e.g. “2” instead of “February”).
  • :use_short_month – Set to true if you want to use the abbreviated month name instead of the full name (e.g. “Feb” instead of “February”).
  • :add_month_number – Set to true if you want to show both, the month‘s number and name (e.g. “2 – February” instead of “February”).
  • :use_month_names – Set to an array with 12 month names if you want to customize month names. Note: You can also use Rails’ new i18n functionality for this.
  • :date_separator – Specifies a string to separate the date fields. Default is “” (i.e. nothing).
  • :start_year – Set the start year for the year select. Default is Time.now.year - 5.
  • :end_year – Set the end year for the year select. Default is Time.now.year + 5.
  • :discard_day – Set to true if you don‘t want to show a day select. This includes the day as a hidden field instead of showing a select field. Also note that this implicitly sets the day to be the first of the given month in order to not create invalid dates like 31 February.
  • :discard_month – Set to true if you don‘t want to show a month select. This includes the month as a hidden field instead of showing a select field. Also note that this implicitly sets :discard_day to true.
  • :discard_year – Set to true if you don‘t want to show a year select. This includes the year as a hidden field instead of showing a select field.
  • : order – Set to an array containing :day, :month and :year do customize the order in which the select fields are shown. If you leave out any of the symbols, the respective select will not be shown (like when you set :discard_xxx => true. Defaults to the order defined in the respective locale (e.g. [:year, :month, :day] in the en locale that ships with Rails).
  • :include_blank – Include a blank option in every select field so it‘s possible to set empty dates.
  • :default – Set a default date if the affected date isn‘t set or is nil.
  • :disabled – Set to true if you want show the select fields as disabled.
  • :prompt – Set to true (for a generic prompt), a prompt string or a hash of prompt strings for :year, :month, :day, :hour, :minute and :second. Setting this option prepends a select option with a generic prompt (Day, Month, Year, Hour, Minute, Seconds) or the given prompt string.

Examples

date_select("post", "written_on")
date_select("post", "written_on", :start_year => 1995)
date_select("post", "written_on", :start_year => 1995,
                       :use_month_numbers => true,
                       :discard_day => true,
                       :include_blank => true)
date_select("post", "written_on", : order => [:day, :month, :year])
date_select("user", "birthday", : order => [:month, :day])
date_select("post", "written_on", :default => 3.days.from_now)
date_select("credit_card", "bill_due",
                    :default => { :day => 20 })
date_select("post", "written_on",
       :prompt => { :day => 'Select day',
                    :month => 'Select month',
                    :year => 'Select year' })
Advertisements