Module: Russian::ActiveModelExt::ErrorPatch

Defined in:
lib/russian/active_model_ext/custom_error_message.rb

Overview

Patch for ActiveModel::Error.full_message. Validation messages prefixed with ‘^` suppress the humanized attribute name in the resulting full message.

Патч для ActiveModel::Error.full_message. Сообщения валидации с префиксом ‘^` подавляют humanized-имя атрибута в итоговом полном сообщении.

Instance Method Summary collapse

Instance Method Details

#full_message(attribute, message, base) ⇒ String

Builds a full validation message and optionally suppresses the attribute name when the message starts with ‘^`.

Строит полное сообщение валидации и при необходимости подавляет имя атрибута, если сообщение начинается с ‘^`.

Examples:

ActiveModel::Error.full_message(:agreement, "^Нужно согласиться с соглашением", record)
# => "Нужно согласиться с соглашением"

Parameters:

  • attribute (String, Symbol)

    Attribute name. Имя атрибута.

  • message (#to_s)

    Validation message. Сообщение валидации.

  • base (Object)

    Model instance. Экземпляр модели.

Returns:

  • (String)

    Full validation message. Полное сообщение валидации.



37
38
39
40
41
# File 'lib/russian/active_model_ext/custom_error_message.rb', line 37

def full_message(attribute, message, base)
  return super unless suppress_attribute_name?(attribute, message)

  message.to_s.delete_prefix("^")
end