代码之家  ›  专栏  ›  技术社区  ›  Pierre P.

使用选项修改验证的错误消息

  •  2
  • Pierre P.  · 技术社区  · 8 年前

    en:
      activerecord:
        attributes:
          user:
            name: "Name"
            email: "E-mail address"
            password: "Password"
            password_confirmation: "Password confirmation"
        errors:
          messages:
            blank: "%{attribute} is required"
            taken: "%{attribute} is already taken"
            invalid: "%{attribute} is not valid"
          models:
            user:
              attributes:
                password:
                  confirmation: "%{attribute} doesn't match confirmation"
    

    然而,我不知道如何修改 在内部 指定范围 http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models )但我不知道怎么做?

    谢谢

    1 回复  |  直到 8 年前
        1
  •  1
  •   Pedro Gabriel Lima    8 年前

    我在我的应用程序中找到了这些标签。其中一个应该适合你!

    equal_to: must be equal to %{count}
    greater_than: must be greater than %{count}
    greater_than_or_equal_to: must be greater or equal to %{count}
    less_than: must be less than %{count}
    less_than_or_equal_to: must be less or equal than %{count}
    too_long:
      one: 'is to short (max than: 1 character)'
      other: 'is to long (max than: %{count} characteres)'
    too_short:
      one: 'is to short (min: 1 character)'
      other: 'is to short (min: %{count} characteres)'
    wrong_length:
      one: doesn't have the right length (1 character)
      other: doesn't have the right length (%{count} characteres)
    other_than: must be different than %{count}