0

I am using Sequel. How do I get ActiveModel-style translated errors?

Example

class User < Sequel::Model
  def validate
    super
    errors.add(:email, :invalid)
  end
end

@user = User.new
@user.save # => false
@user.errors.full_messages # => ["email invalid"]

I want it to return a translated error using the config/locales data. When I18n.locale = :en it should return ["Email is invalid"], when I18n.locale = :de it should return ["Derrrrr E-Reichspost ist ungültig"] (and so on). How can I get translated error messages in sequel?

iblue
  • 29,609
  • 19
  • 89
  • 128

1 Answers1

2

You need to modify the validation_helpers plugin DEFAULT_OPTIONS. Here's an example: http://pastie.org/4251873

Jeremy Evans
  • 11,959
  • 27
  • 26