Saving images locally using the Paperclip gem on Linux
originally shared here on
Like most red-blooded Ruby on Rails developers, I make copious use of the Paperclip gem.
Paperclip (and basically, every developer on the internet) seems to encourage you to use a service like Amazon S3 or some other 3rd party service to store your files.
However, I find that for simple projects, I'm just fine storing the images locally on my Linux server and using good ol' Apache to serve them up.
By default, Paperclip saves these images in your public/system folder, and assigns the same permissions as your Rails app to those images.
The problem I run into is that frequently, it doesn't use the right permissions. I'd be able to upload and save the image, but when I'd load the image, I'd get a 403 error.
In order to solve that issue, you need to set the correct permissions for your public/system/[model] directory.
Here's how to quickly solve that:
1) SSH into your public/system/[model] directory
2) Run "umask 002
". This will allow your Linux group to write into this directory.
3) Run "chgrp [your-systems-group] .
". In my case, that's www-data
. This will change the ownership of the folder to your group.
Now, all the files in your folders (and all subsequently created files) will belong to the correct group, and you won't see any more nasty 403 errors!