Guest User

Untitled

a guest
Jan 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. # Helper method that determines the default error message used by Active
  2. # Record. Works for both existing Rails 2.1 and Rails 2.2 with the newly
  3. # introduced I18n module used for localization.
  4. #
  5. # default_error_message(:blank)
  6. # default_error_message(:too_short, :count => 5)
  7. # default_error_message(:too_long, :count => 60)
  8. def default_error_message(key, values = {})
  9. if Object.const_defined?(:I18n) # Rails >= 2.2
  10. I18n.translate(:"activerecord.errors.messages.#{key}", {:default => :"errors.messages.#{key}"}.merge(values))
  11. else # Rails <= 2.1.x
  12. ::ActiveRecord::Errors.default_error_messages[key] % values[:count]
  13. end
  14. end
Add Comment
Please, Sign In to add comment