2

I have this validation for content type:

validates_attachment_content_type :photo, :content_type => /^image\/(jpg|jpeg|pjpeg|png|x-png|gif)$/, :message => 'file type is not allowed (only jpeg/png/gif images)'

I want only the message above to be displayed but instead it says

 Photos photo content type file type is not allowed (only jpeg/png/gif images)

because its a photos model and attached file photo.

thanks

Jaqx
  • 826
  • 3
  • 14
  • 39

3 Answers3

2
> 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("File '#{self.image_file_name}' is not a valid image type") # or errors.add
>        end
>       end
1

I'm late to this party.

validates_attachment_size :image, :in => 0.megabytes..2.megabytes,  message: " is too large, try less than 2mb  or for help"

Gets you:

Should get you closer to home, with an output of:

"Image file size is too large, try less than 2mb"

jahrichie
  • 1,215
  • 3
  • 17
  • 26
-3

Hello please d validation paperclip avtar image

attr_accessible :avatar

has_attached_file :avatar, :styles => { :small => "60x60>", :thumb => "60x60>" }

validates_attachment :avatar, :presence => true, 
:content_type => { :content_type => "image/jpg" }, 
:size => { :in => 0..1000.kilobytes }  
Bajirao Pheshwe
  • 504
  • 2
  • 10