Sha256: 361fdeff67755b9ed903621c9992b32909d1eb2b338e079a36fbd950e9eca62b

Contents?: true

Size: 1.11 KB

Versions: 38

Compression:

Stored size: 1.11 KB

Contents

module MuckEngine # :nodoc:
  module Models # :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
          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
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
muck-engine-3.5.0 lib/muck-engine/test/models/helpers.rb
muck-engine-3.4.0 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.18 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.17 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.16 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.15 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.14 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.13 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.12 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.11 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.10 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.9 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.8 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.7 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.6 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.5 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.4 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.3 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.2 lib/muck-engine/test/models/helpers.rb
muck-engine-3.3.1 lib/muck-engine/test/models/helpers.rb