【问题标题】:i18n custom validation error handlingi18n 自定义验证错误处理
【发布时间】:2014-02-28 09:34:15
【问题描述】:

在 Rails 3.2.16 应用程序表单提交中,错误消息未经过 i18n 化处理到视图。基于以下模型定义

  validate :not_overlap

  def not_overlap
    errors.add(:start, 'message') if overlaps?
  end

我无法插入翻译代码助手

以下是语言环境文件:

  activerecord:
    models: 
      optionrate: "Options"
    attributes:
      optionrate:
        start: "Start"
        end: "End"
    errors:
      models:
        optionrate:
          attributes:
            start:
              not_overlap: "Dates overlap existing options."
            end:
              not_overlap: "Dates overlap existing options"

我也不确定

<% @optionrate.errors.full_messages.each do |msg| %><%= msg %>

命令及其 i18n...

...哪一种可以让 3 只兔子追赶

  1. 如何调用翻译消息
  2. 如何在语言环境文件中正确编码
  3. 如何处理 i18n 的通用 msg 我假设对于这些如何处理有一个层次结构。结合起来,它是一个几何级数增长的替代方案。

我做错了什么?

【问题讨论】:

    标签: ruby-on-rails-3 error-handling internationalization


    【解决方案1】:

    我认为 errors.add 的第二个参数需要是您尝试添加的错误消息的符号。所以:

    errors.add(:start, :not_overlap)
    

    不过,您现在可能已经解决了这个问题!

    【讨论】:

    • 对;它是钓鱼的字符串或符号......我还没有修复它!谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-23
    • 2021-11-06
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多