Module: Russian::ActionViewExt::Helpers::DateHelperPatch

Defined in:
lib/russian/action_view_ext/helpers/date_helper.rb

Overview

Patch for ActionView::Helpers::DateHelper.

Патч для ActionView::Helpers::DateHelper.

Instance Method Summary collapse

Instance Method Details

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

Builds a ‘<select>` with month options and forces standalone month names for Russian.

The method keeps standard Rails month helper behavior and options, but injects ‘use_standalone_month_names: true` before delegating to Rails. This makes Russian month names render as standalone forms such as `Декабрь` instead of contextual forms such as `декабря`.

Формирует ‘<select>` со списком месяцев и принудительно использует отдельностоящие названия месяцев для русского языка.

Метод сохраняет стандартное поведение и опции Rails month helper’а, но перед делегированием в Rails добавляет ‘use_standalone_month_names: true`. Благодаря этому для русского языка рендерятся отдельностоящие формы вроде `Декабрь`, а не контекстные формы вроде `декабря`.

Examples:

Default Russian output

select_month(Date.new(2024, 12, 1))
# => uses standalone month names for :ru

Custom field name

select_month(Date.new(2024, 12, 1), field_name: "start")
# => overrides the generated field name

Abbreviated standalone month names

select_month(Date.new(2024, 12, 1), use_short_month: true)
# => uses abbreviated standalone month names

Parameters:

  • date (Date, Time, DateTime, Integer, nil)

    Selected month value. Выбранное значение месяца.

  • options (Hash) (defaults to: {})

    Rails helper options. Опции Rails-хелпера.

  • html_options (Hash) (defaults to: {})

    HTML options. HTML-опции.

Options Hash (options):

  • :use_month_numbers (Boolean)

    Show month numbers instead of names. Показывать номера месяцев вместо названий.

  • :add_month_numbers (Boolean)

    Prefix month names with numbers. Добавлять номер месяца перед названием.

  • :use_short_month (Boolean)

    Use abbreviated month names. Использовать сокращенные названия месяцев.

  • :use_month_names (Array<String>)

    Custom month names array. Пользовательский массив названий месяцев.

  • :field_name (String, Symbol)

    Override the field name, ‘“month”` by default. Переопределить имя поля; по умолчанию используется `“month”`.

  • :use_standalone_month_names (Boolean)

    Request standalone month names explicitly. Явно запросить отдельностоящие названия месяцев.

Returns:

  • (String)

    HTML for the select tag. HTML для select-тега.



103
104
105
# File 'lib/russian/action_view_ext/helpers/date_helper.rb', line 103

def select_month(date, options = {}, html_options = {})
  super(date, options.merge(use_standalone_month_names: true), html_options)
end