【问题标题】:Internationalize custom model errors国际化自定义模型错误
【发布时间】:2011-05-20 01:00:12
【问题描述】:

如何处理自定义错误验证的翻译?我可以传递一个符号,然后在我的 yaml 文件中执行某些操作吗? 这是我的代码:

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

格雷格

【问题讨论】:

    标签: ruby-on-rails activerecord error-handling


    【解决方案1】:

    我发现了。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多