gpt4 book ai didi

ruby-on-rails - 更改 Paperclip 中的错误验证消息

转载 作者:行者123 更新时间:2023-12-03 18:31:08 25 4
gpt4 key购买 nike

当您在回形针中设置验证消息时,例如

validates_attachment_presence, :image, :message => 'xxxx'

自定义消息会自动以字段名称作为前缀,即使它已被 :message 覆盖。您如何完全覆盖消息并使其完全自定义?

编辑:错字

最佳答案

不是一个真正的解决方案,但一个简单的解决方案是跳过回形针验证并编写自定义验证。

validate :check_content_type

def check_content_type
if !['image/jpeg', 'image/gif','image/png'].include?(self.image_content_type)
errors.add_to_base("Image '#{self.image_file_name}' is not a valid image type") # or errors.add
end
end

我希望它可以帮助

关于ruby-on-rails - 更改 Paperclip 中的错误验证消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4626377/

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