【问题标题】:How do I change the attributes name for a validation failure message?如何更改验证失败消息的属性名称?
【发布时间】:2017-06-27 22:00:25
【问题描述】:

我试过了

validates :agree_tos, acceptance: {accept: true, message: ->(object, data) {'Terms of Service must be accepted.'}}, allow_nil: false, on: :update

但它说

必须接受服务条款。

我也试过了

validates :agree_tos, acceptance: {accept: true, message: 'Terms of Service'}, allow_nil: false, on: :update

Guide

【问题讨论】:

    标签: ruby-on-rails validation ruby-on-rails-5


    【解决方案1】:

    我在/config/locales/en.yml改了

    en:
      activerecord:
        attributes:
          user:
            agree_tos: "Terms of Service"
    

    使用过

    validates :agree_tos, acceptance: true, allow_nil: false, on: :update
    

    产生

    必须接受服务条款

    【讨论】:

      猜你喜欢
      • 2016-11-02
      • 1970-01-01
      • 2014-11-16
      • 2020-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-04
      相关资源
      最近更新 更多