0

I am trying to attach an image via paperclip. But not working. The default image is showing fine. But I cant upload images using the browse option. Here is the error am getting.

"1 error prohibited this listing from being saved: Image has an extension that does not match its contents"

I have added the validation in model aswell. Here is mylistings.rb which is in models.

class Listing < ActiveRecord::Base

    has_attached_file :image, :styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "default.jpg"
    validates_attachment :image, content_type: { content_type: /\Aimage\/.*\Z/ }
end
Nitish Parkar
  • 2,838
  • 1
  • 19
  • 22
Abhilash
  • 2,864
  • 3
  • 33
  • 67
  • Check [this](http://stackoverflow.com/questions/23629888/validation-failed-upload-file-has-an-extension-that-does-not-match-its-contents) – Nitish Parkar Oct 05 '14 at 13:53

1 Answers1

0

you can use content type validation like this also:

class Listing < ActiveRecord::Base

has_attached_file :image, :styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "default.jpg"
validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]

end

sprytechies
  • 317
  • 3
  • 7