### Home Classes Methods

### In Files

- lib/shoulda/active_record/helpers.rb

### Methods

- #default_error_message

### Files

- CONTRIBUTION_GUIDELINES.rdoc
- README.rdoc

### Class/Module Index

Quicksearch

- Shoulda
- Shoulda::ActionController
- Shoulda::ActionController::Macros
- Shoulda::ActionController::Matchers
- Shoulda::ActionMailer
- Shoulda::ActionMailer::Assertions
- Shoulda::ActionMailer::Matchers
- Shoulda::ActiveRecord
- Shoulda::ActiveRecord::Assertions
- Shoulda::ActiveRecord::Helpers
- Shoulda::ActiveRecord::Macros
- Shoulda::ActiveRecord::Matchers
- Shoulda::Assertions
- Shoulda::ClassMethods
- Shoulda::Helpers
- Shoulda::InstanceMethods
- Shoulda::Macros
- ActionController
- Test

No matching classes.

# Shoulda::ActiveRecord::Helpers

### Public Instance Methods

default_error_message(key, values = {}) click to toggle source

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)

    # File lib/shoulda/active_record/helpers.rb, line 18
    def default_error_message(key, values = {})
      if Object.const_defined?(:I18n) # Rails >= 2.2
        result = I18n.translate("activerecord.errors.messages.#{key}", values)
        if result =~ /^translation missing/
          I18n.translate("errors.messages.#{key}", values)
        else
          result
        end
      else # Rails <= 2.1.x
        ::ActiveRecord::Errors.default_error_messages[key] % values[:count]
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.