Method: ActionView::Helpers::DateTimeSelector#select_year

Defined in:
actionview/lib/action_view/helpers/date_helper.rb

#select_yearObject



840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
# File 'actionview/lib/action_view/helpers/date_helper.rb', line 840

def select_year
  if !year || @datetime == 0
    val = "1"
    middle_year = Date.today.year
  else
    val = middle_year = year
  end

  if @options[:use_hidden] || @options[:discard_year]
    build_hidden(:year, val)
  else
    options         = {}
    options[:start] = @options[:start_year] || middle_year - 5
    options[:end]   = @options[:end_year] || middle_year + 5
    options[:step]  = options[:start] < options[:end] ? 1 : -1

    max_years_allowed = @options[:max_years_allowed] || 1000

    if (options[:end] - options[:start]).abs > max_years_allowed
      raise ArgumentError, "There are too many years options to be built. Are you sure you haven't mistyped something? You can provide the :max_years_allowed parameter."
    end

    build_select(:year, build_year_options(val, options))
  end
end