instance method generate_full_message

Ruby on Rails 2.3.18

Since v2.3.18 Last seen in v2.3.18

Signature

generate_full_message(options = {})

Wraps an error message into a full_message format.

The default full_message format for any locale is "%{attribute} %{message}". One can specify locale specific default full_message format by storing it as a translation for the key :"activerecord.errors.full_messages.format".

Additionally one can specify a validation specific error message format by storing a translation for :"activerecord.errors.full_messages.[message_key]". E.g. the full_message format for any validation that uses :blank as a message key (such as validates_presence_of) can be stored to :"activerecord.errors.full_messages.blank".

Because the message key used by a validation can be overwritten on the validates_* class macro level one can customize the full_message format for any particular validation:

# app/models/article.rb
class Article < ActiveRecord::Base
  validates_presence_of :title, :message => :"title.blank"
end

# config/locales/en.yml
en:
  activerecord:
    errors:
      full_messages:
        title:
          blank: This title is screwed!

Parameters

options opt = {}
Source
# File activerecord/lib/active_record/validations.rb, line 108
      def generate_full_message(options = {})
        keys = [
          :"full_messages.#{@message}",
          :'full_messages.format',
          '%{attribute} %{message}'
        ]

        options.merge!(:default => keys, :message => self.message)
        I18n.translate(keys.shift, options)
      end

Defined in activerecord/lib/active_record/validations.rb line 108 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::Error

Type at least 2 characters to search.

↑↓ navigate · open · esc close