0

我被困住了。我正在使用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

这是我的雾初始化:

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(图片:'someurl.jpg')

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

这有点道理,我假设我遇到了错误,因为 :image 是一个上传的文件。但是,当我尝试相同的操作但用 remote_image_url 替换图像时,我收到此错误:

undefined method `defaults' for Excon:Module

我不知道这是什么意思。想法?

4

0 回答 0