我刚刚注意到,在使用 cap deploy:migrations
将 Rails 应用程序重新部署到生产环境后我通过管理表单上传的任何图像(例如使用头像图像创建推荐),图像链接现在已损坏。只要我不重新部署任何代码,图像就看起来很好,这是不希望的,因为我经常推送代码更改。我认为这与 capistrano 在每次部署的“releases”中创建文件结构的方式有关,但我不确定如何解决此问题。
我也没有跟踪public/uploads
使用 git,因为我不希望在本地主机上使用的虚假内容出现在生产中。
所以,在我最新的代码推送之前,我已经拥有了所有图像,因为我刚刚添加了它们。现在,推送后没有图像:
以下是我认为相关的文件(如果您还需要查看这些文件,请告诉我):
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
最佳答案
默认情况下,Capistrano 链接 public/system
目录。因此,要保留您的图像,只需更改
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
至
def store_dir
"system/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
关于ruby-on-rails - Capistrano 部署后 Carrierwave 上传的图像不会持久,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30511882/