Carrierwave和Heroku不适用于播种

时间:2015-03-07 12:07:09

标签: ruby-on-rails heroku carrierwave seeding

我已经通过这种方式配置了载波上传器:

class PortraitUploader < CarrierWave::Uploader::Base

    # Include RMagick or MiniMagick support:
    include CarrierWave::RMagick
    # include CarrierWave::MiniMagick

    # Choose what kind of storage to use for this uploader:
    storage :file
    # storage :fog

    # Override the directory where uploaded files will be stored.
    # This is a sensible default for uploaders that are meant to be mounted:
    def store_dir
        "#{Rails.root}/public/images/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
    end

    def cache_dir
        "#{Rails.root}/tmp/uploads"
    end
end

我的种子是这样的:

Portrait.create({
    main: true,
    image: open('http://some-image-out-there.jpg'),
    customer: @hatakeda
})

在开发工作中100%。

将我的应用程序上传到Heroku时,我仍然可以使用上传程序手动设置图片,方法是上传或发送网址

然而,您的种子会创建不显示图像的图像网址 - 404错误。

如何让Carrierwave,Heroku和我的种子快乐地合作?

1 个答案:

答案 0 :(得分:1)

您是否尝试在heroku上存储图像?简短的回答:你不能,因为Heroku是只读的(ephemeral writeable filesystem)。如果上传有效,那么在下次部署或工作人员因任何原因重新启动时,这些文件将被清除。看看Carrierwave store images locally not on s3 at heroku