更改回形针中的错误验证消息 [英] Change error validation message in Paperclip

查看:81
本文介绍了更改回形针中的错误验证消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When you set a validation message in paperclip, such as

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

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

The custom message comes automatically prefixed with the name of the field, even though it has been overwritten with the :message . How do you totally override the message and make it totally custom?

错字

推荐答案

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

Not a real solution but a Easy one is to skip paperclip validation and write custom one.

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 

我希望它能对您有所帮助

I hope it can help

这篇关于更改回形针中的错误验证消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆