开发者

Internationalize custom model errors

开发者 https://www.devze.com 2023-01-28 15:30 出处:网络
How can I handle translation of my custom errors validation? Can I pass a symbol and then do something in my yaml files?

How can I handle translation of my custom errors validation? Can I pass a symbol and then do something in my yaml files? 开发者_如何学GoHere is my code:

 def validate
    errors.add(:kind, "something i want to translate") unless KINDS.include?(kind)
  end

Greg


I found out.

errors.add(:kind, I18n.t(:key, :scope => [:activerecord, :model]) unless KINDS.include?(kind)
0

精彩评论

暂无评论...
验证码 换一张
取 消