Carrierwave / Fog - Excon:模块的未定义方法'默认值'

时间:2013-07-12 04:37:13

标签: ruby-on-rails amazon-web-services carrierwave fog

我被困住了。我正在使用carrierwave / fog来实现一个简单的图像上传系统。这是我的上传者:

class OfficeImagesUploader < 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
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

这是我的fog_init:

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',                               # required
    :aws_access_key_id      => ENV['AWSKEY'],                       # required
    :aws_secret_access_key  => ENV['AWSSEC'],                       # required
    :region                 => 'us-east-1'                          # optional, defaults to 'us-east-1'
  }
  # config.fog_directory  = 'temp-cm'                                 # required
  config.fog_public     = false                                     # optional, defaults to true
  # config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}  # optional, defaults to {}
  # config.asset_host   = 'https://assets.example.com'              # optional, defaults to nil
end

CarrierWave.configure {|config| config.fog_directory = 'office-classifieds-development'} if Rails.env.development?
CarrierWave.configure {|config| config.fog_directory = 'office-classifieds-test'} if Rails.env.test?
CarrierWave.configure {|config| config.fog_directory = 'office-classifieds-production'} if Rails.env.production?

以下是我要上传图片的图片模型:

class Image < ActiveRecord::Base
  attr_accessible :office_listing_id, :image, :remote_image_url

  belongs_to :office_listing

  mount_uploader :image, OfficeImagesUploader
end

我遇到两个问题。当我尝试通过

创建图像时

Image.create(image:'someurl.jpg')

未创建图像,图像属性永远不会用url填充,我收到此错误:“无法将nil转换为字符串。”

这有点意义,我认为我遇到了错误,因为:图像是一个上传的文件。但是,当我尝试相同的东西,但用remote_image_url替换图像时,我收到此错误:

undefined method `defaults' for Excon:Module

我不知道这意味着什么。思考?

0 个答案:

没有答案