instance method select_month

Ruby on Rails 3.2.22.5

Since v2.2.3

Available in: v2.2.3 v2.3.18 v3.0.20 v3.1.12 v3.2.22.5 v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

select_month(date, options = {}, html_options = {})

Returns a select tag with options for each of the months January through December with the current month selected. The month names are presented as keys (what’s shown to the user) and the month numbers (1-12) are used as values (what’s submitted to the server). It’s also possible to use month numbers for the presentation instead of names – set the :use_month_numbers key in options to true for this to happen. If you want both numbers and names, set the :add_month_numbers key in options to true. If you would prefer to show month names as abbreviations, set the :use_short_month key in options to true. If you want to use your own month names, set the :use_month_names key in options to an array of 12 month names. Override the field name using the :field_name option, ‘month’ by default.

Examples

# Generates a select field for months that defaults to the current month that
# will use keys like "January", "March".
select_month(Date.today)

# Generates a select field for months that defaults to the current month that
# is named "start" rather than "month".
select_month(Date.today, :field_name => 'start')

# Generates a select field for months that defaults to the current month that
# will use keys like "1", "3".
select_month(Date.today, :use_month_numbers => true)

# Generates a select field for months that defaults to the current month that
# will use keys like "1 - January", "3 - March".
select_month(Date.today, :add_month_numbers => true)

# Generates a select field for months that defaults to the current month that
# will use keys like "Jan", "Mar".
select_month(Date.today, :use_short_month => true)

# Generates a select field for months that defaults to the current month that
# will use keys like "Januar", "Marts."
select_month(Date.today, :use_month_names => %w(Januar Februar Marts ...))

# Generates a select field for months with a custom prompt. Use <tt>:prompt => true</tt> for a
# generic prompt.
select_month(14, :prompt => 'Choose month')

Parameters

date req
options opt = {}
html_options opt = {}
Source
# File actionpack/lib/action_view/helpers/date_helper.rb, line 571
      def select_month(date, options = {}, html_options = {})
        DateTimeSelector.new(date, options, html_options).select_month
      end

Defined in actionpack/lib/action_view/helpers/date_helper.rb line 571 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionView::Helpers::DateHelper

Type at least 2 characters to search.

↑↓ navigate · open · esc close