Module: ActionView::Helpers::DateHelper

Defined in:
lib/localized_frontend/date_helper.rb

Instance Method Summary collapse

Instance Method Details

#select_month(date, options = {}, html_options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/localized_frontend/date_helper.rb', line 2

def select_month(date, options = {}, html_options = {})
  val = date ? (date.kind_of?(Fixnum) ? date : date.month) : ''
  if options[:use_hidden]
    hidden_html(options[:field_name] || 'month', val, options)
  else
    month_options = []
    month_names = options[:use_month_names] || (options[:use_short_month] ? LocalizedFrontend['month_names']['abbreviated']: LocalizedFrontend['month_names']['full'])
    month_names.unshift(nil) if month_names.size < 13
    1.upto(12) do |month_number|
      month_name = if options[:use_month_numbers]
        month_number
      elsif options[:add_month_numbers]
        month_number.to_s + ' - ' + month_names[month_number]
      else
        month_names[month_number]
      end

      month_options << ((val == month_number) ?
        (:option, month_name, :value => month_number, :selected => "selected") :
        (:option, month_name, :value => month_number)
      )
      month_options << "\n"
    end
    select_html(options[:field_name] || 'month', month_options.join, options, html_options)
  end
end