使用 Capistrano 的 Carrierwave 文件
我使用 Rails 3.2 以及 asset 和 Carrierwave 来上传一些图像,它们存储在 /public/uploads/photo/..... 但是当我执行 cap:deploy (使用 capistrano)时,我当前的目录应用程序不包含我上传的文件,因为 capistrano 制作了一个新版本....
=== 更新 ===
毕竟我
在里面使用了这个:部署命名空间
task :symlink_uploads do
run "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
end
及之后:
after 'deploy:update_code', 'deploy:symlink_uploads'
=== 重新更新 ===
@tristam 的解决方案是解决此问题的最佳方法。
I'm using rails 3.2 with asset and carrierwave for upload some images, they store in /public/uploads/photo/.....
but when I do a cap:deploy (with capistrano) my current directory application doesn't contain the files I uploaded, because capistrano make a new version ....
=== Update ===
After all I use this :
inside :deploy namespace
task :symlink_uploads do
run "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
end
and after:
after 'deploy:update_code', 'deploy:symlink_uploads'
=== Re Update ===
The solution of @tristanm is the best way to solve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
怎么样:
:shared_children
默认为%w(public/system log tmp/pids)
所以我们只是扩展这个列表。编辑:
更改
:shared_children
后,不要忘记运行cap deploy:setup
,以便在shared< 下创建新目标/代码>。
编辑 Capistrano 3:
Capistrano 3 使用
linked_dirs
设置,并且不再将public/system
指定为默认值。set :linked_dirs, fetch(:linked_dirs) + %w{public/system public/uploads}
How about this:
:shared_children
defaults to%w(public/system log tmp/pids)
so we're just expanding this list.EDIT:
Don't forget to run
cap deploy:setup
after changing:shared_children
so that the new targets are created undershared
.EDIT Capistrano 3:
Capistrano 3 uses the
linked_dirs
setting and doesn't specifypublic/system
as a default anymore.set :linked_dirs, fetch(:linked_dirs) + %w{public/system public/uploads}
使用 Capistrano 3,无需重新部署。
就像 @tristam 提到的,将其添加到您的 config/deploy.rb
让 capistrano 创建共享/公共/上传
cap deploy:check:linked_dirs
现在 cap 可以创建符号链接
cap deploy:symlink:shared
最后,如果您有上传的备份,您可以将它们放在共享/公共/上传/中,它们应该可以工作而无需重新部署。
With Capistrano 3 and without needing to redeploy.
Like @tristanm mentioned add this to your config/deploy.rb
To have capistrano create shared/public/uploads
cap deploy:check:linked_dirs
Now cap can create the symlink
cap deploy:symlink:shared
Finally, if you have backups of the uploads you can put them in shared/public/uploads/ and they should work without needing to redeploy.
Capistrano 为每个部署创建新目录。
但也有一些例外。例如,日志文件在部署目录之间共享,因为它们只是符号链接。您还必须为公共/上传创建符号链接。
这是命令:
Capistrano creates new directory for every deploy.
There are some exceptions to it. For example, the log files are shared between the deployment directories because they are just symlinks. You have to create a symlink for public/uploads as well.
Here is the command:
转到您的应用服务器共享文件夹并创建上传目录。
mkdir uploads
在您的deploy.rb文件中,在部署命名空间下插入这些代码
任务:symlink_uploads执行
“rm -rf” #{latest_release}/public/uploads && ln -nfs #{shared_path}/uploads #{latest_release}/public/uploads"
结束
之后 'deploy:update_code', 'deploy:symlink_uploads'
现在删除已经存在的旧文件,因为它们将不起作用。上传新文件并再次部署您的应用程序。现在应该可以了。
Go to your app server shared folder and create an uploads directory.
mkdir uploads
In your deploy.rb file insert these codes under deploy namespace
task :symlink_uploads do
run "rm -rf #{latest_release}/public/uploads && ln -nfs #{shared_path}/uploads #{latest_release}/public/uploads"
end
after 'deploy:update_code', 'deploy:symlink_uploads'
Now delete the old files present already as they won't work. Upload a new file and cap deploy your app again. It should work now.
使用 Capistrano 3,我刚刚将此行添加到我的 config/deploy.rb
然后,运行:
Using Capistrano 3, I just added this line to my config/deploy.rb
Then, run: