[英]Carrierwave uploaded Images aren't persistent after Capistrano deploy
I've just noticed that after I redeploy my rails app to production with cap deploy:migrations
any image that I've uploaded via my admin forms (such as creating a testimonial with an avatar image) that the image links are now broken. 我刚刚注意到,在我将我的Rails应用重新部署到具有cap deploy:migrations
生产之后, cap deploy:migrations
了我通过管理表单上传的任何图像(例如,使用头像图像创建推荐),这些图像链接现在已断开。 The images appear fine as long as I don't redeploy any code, which is not desired since I push code changes quite frequently. 只要不重新部署任何代码,图像就可以正常显示,这是不希望的,因为我经常更改代码。 I assume this is related to the way capistrano creates the file structure in 'releases' for each deployment but I'm not sure how to go about fixing this issue. 我认为这与capistrano为每个部署在“版本”中创建文件结构的方式有关,但是我不确定如何解决此问题。
I'm also not tracking public/uploads
with git since I don't want the fake content I use on localhost to appear in production. 我也不用git跟踪public/uploads
,因为我不希望在本地主机上使用的虚假内容出现在生产环境中。
So, before my latest code push, I had all the images there since I just added them. 因此,在我进行最新代码推送之前,自从我添加所有图像以来,我就已经拥有了所有图像。 Now, after the push there are no images: 现在,在推送之后没有图像:
Here are the files that I believe are relevant (let me know if there is one that you need to see beyond these): 以下是我认为相关的文件(让我知道是否需要查看这些文件之外的文件):
avatar_uploader.rb: avatar_uploader.rb:
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
process :resize_to_fit => [200, 200]
def extension_white_list
%w(jpg jpeg gif png)
end
end
By default, Capistrano links public/system
directory. 默认情况下,Capistrano链接public/system
目录。 So to persist your images, just change 因此,要保留您的图像,只需进行更改
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
to 至
def store_dir
"system/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
Seems like you don't configure linked_dirs
variable in your deploy.rb (in case of Capistrano 3 ) or not specify sym-link to your public/uploads
from shared/public/uploads
(in case of Capistrano 2). 似乎您没有在deploy.rb中配置linked_dirs
变量(在Capistrano 3的情况下),或者未从shared/public/uploads
中指定到public/uploads
的符号链接(在Capistrano 2的情况下)。
Without it all deploy will "override" public/uploads
directory. 没有它,所有deploy都将“覆盖” public/uploads
目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.