instance method weekday_options_for_select

Ruby on Rails 7.2.3

Since v7.0.10

Available in: v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

weekday_options_for_select(selected = nil, index_as_value: false, day_format: :day_names, beginning_of_week: Date.beginning_of_week)

Returns a string of option tags for the days of the week.

Options

  • :index_as_value - Defaults to false, set to true to use the indexes from I18n.translate("date.day_names") as the values. By default, Sunday is always 0.

  • :day_format - The I18n key of the array to use for the weekday options. Defaults to :day_names, set to :abbr_day_names for abbreviations.

  • :beginning_of_week - Defaults to Date.beginning_of_week.

NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.

Parameters

selected opt = nil
index_as_value key = false
day_format key = :day_names
beginning_of_week key = Date.beginning_of_week
Source
# File actionview/lib/action_view/helpers/form_options_helper.rb, line 614
      def weekday_options_for_select(selected = nil, index_as_value: false, day_format: :day_names, beginning_of_week: Date.beginning_of_week)
        day_names = I18n.translate("date.#{day_format}")
        day_names = day_names.map.with_index.to_a if index_as_value
        day_names = day_names.rotate(Date::DAYS_INTO_WEEK.fetch(beginning_of_week))

        options_for_select(day_names, selected)
      end

Defined in actionview/lib/action_view/helpers/form_options_helper.rb line 614 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionView::Helpers::FormOptionsHelper

Type at least 2 characters to search.

↑↓ navigate · open · esc close