Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change error validation message in Paperclip

When you set a validation message in paperclip, such as

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

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?

Edit: typo

like image 651
MintDeparture Avatar asked Jan 07 '11 14:01

MintDeparture


1 Answers

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

like image 97
andrea Avatar answered Oct 04 '22 21:10

andrea