views:

174

answers:

3

Setting up paperclip to use S3 on my local dev system was a snap. However, I am not able to get it to work on Heroku.

The file uploads successfully:

[paperclip] Saving attachments.
[paperclip] saving photos/2/small.jpg
[paperclip] saving photos/2/original.jpg

However, views that try to link to the upload get a routing error:

ActionController::RoutingError (No route matches "/photos/small/missing.png" with {:method=>:get}):

Notice how it is using 'missing' for the file name and is using '.png' for the extension even though the file is a '.jpg'.

I have tried numerous combinations of the :url and :path options with has_attached_file according the various blog posts and tutorials I have found (including Heroku's docs), but none seem to work.

What are the correct steps to use paperclip with S3 on Heroku?

A: 

Can you paste the code from your form please? I'm guessing that you have forgotten to add :html => {:multipart => true}) to the form_for tag

stephenmurdoch
Thanks for replying, but no, that is not the answer. My forms are set up correctly, and as I stated, everything works fine on my dev system. The issue appears to only happen with Heroku.
eksatx
ok, i see. can you confirm whether or not the images are being uploaded to your s3 production bucket? You can do this using s3Fox (a firefox addon). Also, are you using an S3.yml file or config-vars?
stephenmurdoch
I installed S3Fox. How do I tell if images were actually uploaded? I am using S3.yml.I think this specific problem is actually caused by something I tried in order to solve a different problem. Please see http://stackoverflow.com/questions/3580592/model-missing-required-attr-accessor-for-photo-file-name-when-uploading-with-pa for details.
eksatx
A: 

Found the problem: needed to update the database.

heroku rake:db:migrate
heroku restart

I had done what I thought would have accomplished the same thing already: heroku rake db:schema:load, but perhaps that doesn't work or something went wrong in the process.

Anyhow, doing that, along with removing the calls to attr_accessor as suggested on another blog, solved the problem.

eksatx
A: 

I just had this exact same problem. Ran fine in dev, uploaded files to s3 in prod but wouldn't show the URL for uploaded images. Running

heroku restart

was what fixed it. No need to run db:migrate (unless, of course, you need to migrate the database).

Thanks for the info!

mm53bar