【问题标题】:Carrierwave uploaded Images aren't persistent after Capistrano deploy在 Capistrano 部署后,Carrierwave 上传的图像不持久
【发布时间】:2015-05-28 16:10:58
【问题描述】:

我刚刚注意到,在我使用 cap deploy:migrations 将我的 rails 应用程序重新部署到生产环境后,我通过管理表单上传的任何图像(例如使用头像图像创建推荐)现在图像链接已损坏.只要我不重新部署任何代码,图像看起来就很好,这是不希望的,因为我经常推送代码更改。我认为这与 capistrano 在“发布”中为每个部署创建文件结构的方式有关,但我不确定如何解决这个问题。

我也没有使用 git 跟踪 public/uploads,因为我不希望我在 localhost 上使用的虚假内容出现在生产中。

所以,在我最新的代码推送之前,我有所有的图像,因为我刚刚添加了它们。现在,推送后没有图片了:

以下是我认为相关的文件(如果您需要查看这些文件,请告诉我):

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

【问题讨论】:

    标签: ruby-on-rails ruby image capistrano rubber


    【解决方案1】:

    默认情况下,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
    

    【讨论】:

      【解决方案2】:

      似乎您没有在 deploy.rb 中配置linked_dirs 变量(在Capistrano 3 的情况下),或者没有从shared/public/uploads 指定到public/uploads 的符号链接(在Capistrano 2 的情况下)。

      没有它,所有部署都将“覆盖”public/uploads 目录。

      Here 更详细。

      【讨论】:

        猜你喜欢
        • 2018-04-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-29
        • 2021-07-20
        相关资源
        最近更新 更多