问题描述
我使用Paperclip宝石来存储图片,而在localhost上,它是完美的。但是,我添加到我的直播应用程序的任何图片都会在每次部署后被删除。
I use the Paperclip gem to store pictures, and on localhost it works perfectly. However, any pictures I add to my live app get deleted after every deploy.
我使用Git进行部署。这是我的部署过程:
I use Git to deploy. Here's my deployment process:
$ bundle exec cap production deploy
$ ssh [email protected]
$ chmod -R 777 /rails_apps/app/releases
$ cd /rails_apps/app/current
$ cp config/database.yml.sample config/database.yml
$ RAILS_ENV=production bundle exec rake assets:precompile
$ /etc/init.d/apache2 restart
有没有人遇到这样的事情?
Has anyone else run into something like this?
更新:
这不是重复的,因为,这是将此行添加到我的deploy.rb:
This is not a duplicate, because the answer to this question, which is to add this line to my deploy.rb:
set :linked_dirs, fetch(:linked_dirs, []).push('public/system')
导致Paperclip完全打破。以前,我没有权限使用Paperclip添加图像,导致了以下错误:
causes Paperclip to break entirely. Previously I had had an issue with not having permission to add images with Paperclip, resulting in this error:
Errno::EACCES in UsersController#update
Permission denied - /rails_apps/website/releases/20150807211111/public/system/users/avatars/000/000/562
但是在我的服务器上运行这个命令修复了权限:
But running this command on my server fixes the permissions:
chmod -R 777 /rails_apps/website/releases
但是,如上所示修改我的deploy.rb文件, code> chmod -R 777 命令不再工作,我再次没有权限添加图像,导致相同的权限被拒绝错误。
However, modifying my deploy.rb file as shown above, causes the chmod -R 777
command to no longer work, and I once again don't have permission to add images, resulting in the same "Permission denied" error.
所以这个问题不能为我的问题提供一个有效的解决方案。
So that question does not supply a valid solution to my problem.
推荐答案
在这里:
set :linked_dirs, fetch(:linked_dirs, []).push('public/system')
是实现y将您的公共/系统文件夹从 / rails_apps / website / releases / 20150807211111 / public / system
链接到 / rails_apps / website / shared / public / system
,使图片始终存储在共享目录中,而不会在部署时丢失。所以你应该实际做的是为共享文件夹设置适当的权限。
is actually symlinking your "public/system" folder from /rails_apps/website/releases/20150807211111/public/system
to /rails_apps/website/shared/public/system
, so that the pictures are always stored in the shared directory, and not lost on deploy. So what you should actually do is set the proper rights for the shared folder.
这篇关于Paperclip文件在每次部署后都会被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!