0

我正在为这个设置而苦苦挣扎,并且已经阅读了 Carrierwave 文档并且仍然拉扯头发。即使在开发模式下也尝试启动服务器时出现错误。

退出 /Users/my-machine/.rvm/gems/ruby-1.9.3-p327/gems/carrierwave-0.7.1/lib/carrierwave/uploader/configuration.rb:73:in `eval':无法转换零到字符串(TypeError)

这是我的设置。

配置/初始化程序/carrierwave.rb

S3_CONFIG = YAML.load_file(Rails.root.join('config', 'amazon_s3.yml'))[Rails.env]

CarrierWave.configure do |config|
  config.storage              = :s3
  config.s3_access_policy     = :public_read
  config.s3_access_key_id     = S3_CONFIG['access_key_id']
  config.s3_secret_access_key = S3_CONFIG['secret_access_key']
  config.s3_bucket            = S3_CONFIG['bucket']
  config.s3_region           = 'us-east-1'
end

配置/amazon_s3.yml

development:
  access_key_id: xxxxxxxxxxxxxxxxxxx
  secret_access_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  bucket: dev-bucket

test:
  access_key_id: xxxxxxxxxxxxxxxxxxx
  secret_access_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  bucket: test-bucket

production:
  access_key_id: xxxxxxxxxxxxxxxxxxx
  secret_access_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  bucket: prod-bucket

应用程序/上传器/image_uploader.rb

class ImageUploader < CarrierWave::Uploader::Base
  # 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
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  # fix for Heroku, unfortunately, it disables caching, 
  # see: https://github.com/jnicklas/carrierwave/wiki/How-to%3A-Make-Carrierwave-work-on-Heroku
  def cache_dir
    "#{Rails.root}/tmp/uploads"
  end
end
4

1 回答 1

0

您如何在开发环境中建立 S3_CONFIG 环境变量?好像你失踪了。

于 2013-01-28T18:31:20.227 回答