Exception: Mongoid::Errors::MongoidError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/mongoid/errors/mongoid_error.rb

Overview

Default parent Mongoid error for all custom errors. This handles the base key for the translations and provides the convenience method for translating the messages.

Constant Summary collapse

BASE_KEY =
"mongoid.errors.messages"

Instance Method Summary collapse

Instance Method Details

#translate(key, options) ⇒ String

Given the key of the specific error and the options hash, translate the message.

Examples:

Translate the message.

error.translate("errors", :key => value)

Parameters:

  • key (String)

    The key of the error in the locales.

  • options (Hash)

    The objects to pass to create the message.

Returns:

  • (String)

    A localized error message string.



21
22
23
# File 'lib/mongoid/errors/mongoid_error.rb', line 21

def translate(key, options)
  ::I18n.translate("#{BASE_KEY}.#{key}", options)
end