gpt4 book ai didi

ruby-on-rails - Rails 覆盖验证消息

转载 作者:行者123 更新时间:2023-12-03 07:46:25 26 4
gpt4 key购买 nike

我想在验证消息中看到无效值。

validates_uniqueness_of :event, :scope => :user_id

结果:“标题已被占用”我想:“#{user} 已接受事件 #{event}”

我正在尝试这样做,但发髻不起作用:

validates_uniqueness_of :event, :scope => :user_id, :message=>"#{self.event} already has been taken by #{self.user}"

最佳答案

来自ActiveRecord源代码注释:

The values :model, :attribute and :value are always available for interpolation The value :count is available when applicable. Can be used for pluralization.

所以你可以简单地将你的消息写成

validates_uniqueness_of :event, :scope => :user_id, 
:message=>"{{value}} is already taken"

关于ruby-on-rails - Rails 覆盖验证消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4167651/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com