instance method
weekday_options_for_select
Ruby on Rails 8.0.4
Since v7.0.10Signature
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 fromI18n.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_namesfor 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
-
selectedopt = nil -
index_as_valuekey = false -
day_formatkey = :day_names -
beginning_of_weekkey = Date.beginning_of_week
Source
# File actionview/lib/action_view/helpers/form_options_helper.rb, line 615
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 615
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::Helpers::FormOptionsHelper