2

I am running this code in my model on an after_update call:

require 'rmagick'
file = photo.url(:thumb) #created by paperclip
img = Magick::Image.read(file).first

and I get unable to open file `/assets/contacts/1/thumb/image.png' though that file is there and is used throughout the rest of the app, so I don't suspect permissions as an issue. Rails is looking at my assets directory for everything else, and I can access the image via direct URL on my local box, so I know it exists. I do have ImageMagick installed via homebrew, and I ran "identify -list format" and the formats seem to be installed too. I have added it to the gemfile and run bundle install as well. What other things could I try to troubleshoot this?

How do I know what directory RMagick thinks is root, or is there some other reason why I can't read the file? I have read all I can find on Google, forums, Stack, IRC, and no one seems to have an answer.

Ryan
  • 3,153
  • 2
  • 23
  • 35

1 Answers1

0

Paperclip gem stores uploaded images in public folder. So, if your image path inside public folder is: contacts --> 1 --> thumb --> image.png

Than, you should use path '/contacts/1/thumb/image.png' . Because, if there is no forward slash in URL than rails will by default search inside the assets folder for images.

Rajat
  • 1,378
  • 4
  • 17
  • 33