lib/shoulda/matchers/active_model/helpers.rb
# Helper method that determines the default error message used by Active
# Record.  Works for both existing Rails 2.1 and Rails 2.2 with the newly
# introduced I18n module used for localization.
#
#   default_error_message(:blank)
#   default_error_message(:too_short, :count => 5)
#   default_error_message(:too_long, :count => 60)
#   default_error_message(:blank, :model_name => 'user', :attribute => 'name')
Helper method that determines the default error message used by Active
Record.  Works for both existing Rails 2.1 and Rails 2.2 with the newly
introduced I18n module used for localization.


Helper method that determines the default error message used by Active Record . Works for both existing Rails 2 . 1 and Rails 2 . 2 with the newly introduced I18n module used for localization .
def default_error_message(key, options = {})
          model_name = options.delete(:model_name)
          attribute = options.delete(:attribute)
          default_translation = [ :"activerecord.errors.models.#{model_name}.#{key}",
                                  :"activerecord.errors.messages.#{key}",
                                  :"errors.attributes.#{attribute}.#{key}",
                                  :"errors.messages.#{key}" ]
          I18n.translate(:"activerecord.errors.models.#{model_name}.attributes.#{attribute}.#{key}",
            { :default => default_translation }.merge(options))
        end
def default_error_message ( key , options = { } ) model_name = options . delete ( :model_name ) attribute = options . delete ( :attribute ) default_translation = [ :" activerecord.errors.models. #{ model_name } . #{ key } " , :" activerecord.errors.messages. #{ key } " , :" errors.attributes. #{ attribute } . #{ key } " , :" errors.messages. #{ key } " ] I18n . translate ( :" activerecord.errors.models. #{ model_name } .attributes. #{ attribute } . #{ key } " , { :default => default_translation } . merge ( options ) ) end
Helper method that determines the default error message used by Active
Record.
Helper method that determines the default error message used by Active Record .
key
<not_specific>
options
<not_specific>