logo

Paperclip and the busted “not recognized by identify” error, and a couple other gotchas

logo

If you’re using the Paperclip Gem, hopefully you won’t have the hours of stumpage I incurred. Here’s something for the Google information vat to swallow.

1. “Not recognized by identify”: This one is resulting from a call to ImageMagick (you did know ImageMagic was required, right?) and a bad relationship with Passenger. The easiest way to resolve this is to place the following line in your appropriate environment files (ie. config/environments/development.rb) making sure that it point to your local instance of Imagemagic. For my development environment on OSX it was:

Paperclip.options[:command_path] = "/opt/local/bin"

(I’m using imagemagic from a MacPorts install; if you are on a linux distro you may need to reference /usr/local/bin.)

1.5 “Not recognized by identify” is also caused when you specify “styles” for a has_attached_file type other than a photo. I’m really not sure how to get around this one, but if you are going to use any file types other than images using the following string in your model will cause the error:

:styles => { :large => "300x300", :medium => "200x200", :thumb => "128x128>", :micro => "40x40#"}

2. Don’t name your model “attachment”: I googled around forever trying to figure this one out. In the end it seems to be a namespace error between Paperclip and the app – Paperclip won. I named the mode “client_attachment”.

3. Remember to include your attachment type in you attr_accessible declaration: If you are protecting against mass assignment you’ve an attr_accessible line in your model. Be sure to include the name of the field you’re using for the attachment in the declaration. For example, if you’re using a “photo” for the Paperclip attachment, be sure to add “:photo” to your attr_accessible declaration:

attr_accessible :first_name, :last_name, ..., :photo
  • heedspin
    I had the same issue: Have an attachment that can be an image or pdf. Wanted processing on the images, but not on the pdfs. Adding :whiny => false to my has_attached_file options silenced the exceptions. This is an acceptable solution in my case.
blog comments powered by Disqus
logo
logo
Powered by Wordpress