0

I have a model that accepts either a photo or video. It works okay, but I think it's getting caught up on the validations.

For photos, I have this:

has_attached_file :content, styles: { thumb: '275x185#' }

Which works great, but saving something with a video produces:

Validation failed: Content Paperclip::Errors::NotIdentifiedByImageMagickError, Content Paperclip::Errors::NotIdentifiedByImageMagickError

I think this is because it's trying to size the video's dimensions. Is it possible to only define the thumb size for content that is an image, but ignore it when it is a video? Or do I have to make two different fields, one photo one video, and have nil's in my DB?

Logan Serman
  • 29,447
  • 27
  • 102
  • 141
  • Maybe this will help but i kinda guess you already saw it: http://stackoverflow.com/questions/7149985/use-single-attachment-for-video-image-in-paperclip EDIT: doesn't address your problem, sorry. – Zippie Mar 12 '13 at 18:33

1 Answers1

1

styles can be given a lambda to perform conditional processing:

has_attached_file :content, styles: lambda do |a|
  if ['image/jpeg', 'image/jpg', 'image/gif', 'image/png'].include? a.instance.content_content_type
    { thumb: '275x185#'}
  end  
end

However, the method used here to check if content is an image may be inaccurate.

Ilya Khokhryakov
  • 3,686
  • 1
  • 19
  • 22