21

我不确定如何配置环境,以便 Carrier Wave 在本地运行应用程序(开发)和加载到 heroku(生产)后的 s3 时使用本地文件存储

在开发存储中:文件

在生产存储中:s3

4

3 回答 3

24

无论是模型,还是您可以全局设置它。在https://github.com/jnicklas/carrierwave/tree/v0.5.2查看 v0.5.2(当前 gem)的自述文件

在底部附近,有一些配置测试环境的说明。使用相同的方法为“开发”和“生产”使用不同的配置,例如将文件“carrierwave.rb”添加到“config/initialisers”并添加配置代码

if Rails.env.test? or Rails.env.cucumber?
  CarrierWave.configure do |config|
    config.storage = :file
    config.enable_processing = false
  end
end

和发展

if Rails.env.development?
  CarrierWave.configure do |config|
    config.storage = :file
  end
end

和生产

if Rails.env.production?
  CarrierWave.configure do |config|
    config.storage = :s3
  end
end
于 2011-03-20T21:05:14.697 回答
8

我通常做的最简单的方法是通过上传器。

class CoverUploader < CarrierWave::Uploader::Base
  # Choose what kind of storage to use for this uploader:
  storage (Rails.env.production? ? :fog : :file)
end
于 2013-05-05T01:03:25.857 回答
1

我猜这是在某处的模型中设置的。你可以做类似的事情

if Rails.env.production?
  // set production
else
  // set dev / test
end
于 2011-03-20T20:06:09.507 回答