Sha256: e8faedb1d19cd5d79f9e0318eacbd0f011d0c9e791990143087d16be6f6b64cb

Contents?: true

Size: 979 Bytes

Versions: 38

Compression:

Stored size: 979 Bytes

Contents

module Shoulda # :nodoc:
  module ActiveRecord # :nodoc:
    module Helpers
      def pretty_error_messages(obj) # :nodoc:
        obj.errors.map do |a, m| 
          msg = "#{a} #{m}" 
          msg << " (#{obj.send(a).inspect})" unless a.to_sym == :base
        end
      end

      # 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)
      def default_error_message(key, values = {})
        if Object.const_defined?(:I18n) # Rails >= 2.2
          I18n.translate("activerecord.errors.messages.#{key}", values)
        else # Rails <= 2.1.x
          ::ActiveRecord::Errors.default_error_messages[key] % values[:count]
        end
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 10 rubygems

Version Path
thoughtbot-shoulda-2.10.2 lib/shoulda/active_record/helpers.rb
lockbox_middleware-1.2.1 vendor/gems/shoulda-2.10.2/lib/shoulda/active_record/helpers.rb
robert-shoulda-2.10.4 lib/shoulda/active_record/helpers.rb
robert-shoulda-2.10.3 lib/shoulda/active_record/helpers.rb
simply_stated-0.0.5 vendor/gems/ruby/1.8/gems/shoulda-2.10.3/lib/shoulda/active_record/helpers.rb
simply_stated-0.0.4 vendor/gems/ruby/1.8/gems/shoulda-2.10.3/lib/shoulda/active_record/helpers.rb
shoulda-2.10.3 lib/shoulda/active_record/helpers.rb
tpitale-shoulda-2.11.0 lib/shoulda/active_record/helpers.rb
shoulda-2.10.2 lib/shoulda/active_record/helpers.rb
poolparty-1.3.15 vendor/gems/shoulda/lib/shoulda/active_record/helpers.rb
poolparty-1.3.14 vendor/gems/shoulda/lib/shoulda/active_record/helpers.rb
poolparty-1.3.13 vendor/gems/shoulda/lib/shoulda/active_record/helpers.rb
poolparty-1.3.8 vendor/gems/shoulda/lib/shoulda/active_record/helpers.rb
poolparty-1.3.7 vendor/gems/shoulda/lib/shoulda/active_record/helpers.rb
poolparty-1.3.6 vendor/gems/shoulda/lib/shoulda/active_record/helpers.rb
poolparty-1.3.4 vendor/gems/shoulda/lib/shoulda/active_record/helpers.rb
poolparty-1.3.3 vendor/gems/shoulda/lib/shoulda/active_record/helpers.rb
poolparty-1.3.1 vendor/gems/shoulda/lib/shoulda/active_record/helpers.rb