3

我正在使用带有 mongoid 支持的 Carrierwave

gem "carrierwave-mongoid", :git => "git://github.com/jnicklas/carrierwave-mongoid.git", :branch => "mongoid-3.0",:require => 'carrierwave/mongoid'

我将carrierwave配置为将雾存储与AWS(S3)一起使用

# config/initializers/carrierwave.rb
CarrierWave.configure do |config|
    config.storage = :fog
    config.root = Rails.root.join('tmp') # adding these...
    config.cache_dir = 'carrierwave' # ...two lines
    config.fog_credentials = {
        :provider => 'AWS',
        :aws_access_key_id => '',
        :aws_secret_access_key => ''
    },
    config.fog_directory = 'alzheimer'
end

我有一个名为 Picture 的类与上传器和上传器一起使用

class ImagenUploader < CarrierWave::Uploader::Base
    include CarrierWave::MimeTypes
    include CarrierWave::RMagick
    storage :fog
    process :set_content_type
    process :convert => 'png'
    def filename
        super.chomp(File.extname(super))+'.png'
    end
    version :thumb do
        process :resize_to_fit => [24,24]
    end
end

而我的图片模型类图片包括 Mongoid::Document 包括 Mongoid::Timestamps 包括 Mongoid::Paranoia belongs_to :user

     field :descripcion, :type => String
     field :titulo, :type => String
     field :imagen, :type => String

     attr_accessible :imagen, :imagen_cache, :descripcion, :titulo
     mount_uploader :imagen, ImagenUploader
 end

我尝试上传图片,广告我得到:

ArgumentError: is not a recognized storage provider
from /Users/msdark/.rvm/gems/ruby-1.9.3-p194/gems/fog-1.5.0/lib/fog/storage.rb:33:in new'
from /Users/msdark/.rvm/gems/ruby-1.9.3-p194/gems/carrierwave-0.6.2/lib/carrierwave/storage/fog.rb:106:inconnection'

我使用 rails 3.2.8 ruby​​ 1.9.3p194 和 unicorn (4.3.1)

上传后尝试显示此错误:

image_tag(picture.imagen_url)

任何想法?

编辑:

宝石文件

source 'https://rubygems.org'
gem 'rails', '3.2.8'
group :assets do
   gem 'sass-rails',   '~> 3.2.3'
   gem 'coffee-rails', '~> 3.2.1'
   gem 'therubyracer', :platform => :ruby
   gem 'uglifier', '>= 1.0.3'
   gem 'jquery-rails'
   gem 'jquery-ui-rails'
   gem 'less-rails-bootstrap'
end

gem 'unicorn'
gem 'heroku'
gem 'foreman'

gem 'i18n'
gem 'formtastic'
gem "activeadmin-mongoid",  git: "git://github.com/elia/activeadmin-mongoid.git"
gem 'mongoid'
gem 'bson_ext'
gem 'devise'
gem 'devise-i18n'
gem 'omniauth'
gem 'omniauth-twitter'
gem 'omniauth-facebook'

gem "carrierwave-mongoid", :git => "git://github.com/jnicklas/carrierwave-mongoid.git", :branch => "mongoid-3.0", :require => 'carrierwave/mongoid'
gem 'mini_magick', :git => 'git://github.com/probablycorey/mini_magick.git'

gem 'recaptcha',            :require => 'recaptcha/rails'
gem 'googlecharts'

group :test do 
gem 'capybara'
gem 'database_cleaner'
gem 'mongoid-rspec'
gem 'launchy'
gem 'factory_girl_rails'
gem 'mongoid-rspec'
gem 'faker'
end 
gem 'rspec-rails',:group =>[:development,:test]
4

1 回答 1

2

我有一个类似的问题。事实证明,我的上传器没有与配置中定义的内容匹配的存储引擎。我在 Carrierwave 配置中(在初始化程序中)做了一个窥探,并查看了 storage_engines。

[5] pry(main)> config.storage_engines
=> {:file=>"CarrierWave::Storage::File", :fog=>"CarrierWave::Storage::Fog"}

然后我确保上传者的设置与此处的条目之一匹配。所以在你的情况下,如果你有

class ImagenUploader < CarrierWave::Uploader::Base
  ...
  storage :fog
  ...
end

那么您需要确保:fog在您使用的配置上下文中有一个条目。你可以从那里回溯。

我意识到这是一个稍微老一点的问题,但如果你还没有弄清楚,我希望这会有所帮助。

于 2012-11-03T05:22:55.467 回答