Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I configure paperclip with capistrano?

Cristian Georgescu asked in Servers

Hi,

I deployed using the "Deploy Ruby on Rails" guide.
However I paperclip attachments no longer work in production. Got the below error:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)

Any suggestions ?

Thanks.
PS:
Also I don't know where exactly I can check the logs. current/log/production is empty

Reply

You have to make sure that you symlink the paperclip uploads folder each deploy so your files don't get lost. They create a folder on your server and then every deploy the Rails app is deployed to a new folder, meaning you lose those old files.

Add this to your config/deploy.rb and it will symlink the directory each time so your files won't disappear.

set :linked_dirs, fetch(:linked_dirs, []).push('public/system')
Reply

Thank you for your reply Olvier.
I added the line to deploy.rb and also I checked the server.
public/system is present in current folder, in shared and also on releases but the issue persists.
Do I need to create the also the folder for :class and :partition inside the public/system?
Can it be a folder permissions issue ?

Thank you,
Cristian

Reply

Well if you've done that, you also need to salvage the old file uploads by moving them from one the old releases folders and move them into the new public/system folder that's being symlinked. That's likely why your image still don't work. Kind of a pain as well.

If you are just using test data, you can try reuploading an image, doing a new deploy, and making sure that image still works.

Reply

Still not working. I don't want to salvage old images.
I want to upload new ones once I create a registration.

Is there a way to check the logs to see what is happening ?

Reply

Yeah your logs/production.log (assuming you're running the production environment in your web server) file should have the actual error in it. Sometimes that file won't be written for a variety of reasons, so you might have to fix that first. I can't remember what the solutions were, but you can google for the empty production.log file and find some solutions on StackOverflow.

Reply

It works.

After checking the logs found out that a call to imagemagik was the culprit.
Works don't work by default.
There where 2 issues: rails12_factor gem was installed and it's no longer needed on Rails 5
Also the following ENV vars need to be set in order to get the logs inside the current/logs

RAILS_SERVE_STATIC_FILES and RAILS_LOG_TO_STDOUT ENV need to be true.

Reply

Awesome! Yeah, the 12factor gem is useful for Heroku, but if you run your own server you don't want it as it won't write to that file.

Glad you got it working!

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.