我正在使用带有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
我尝试上传图片,ad i get:
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 红宝石1.9.3p194 和独角兽(4.3.1)
上传后尝试显示错误时显示错误:
image_tag(picture.imagen_url)
有什么想法吗?
编辑:
的Gemfile
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]
答案 0 :(得分:2)
我有类似的问题。事实证明我的上传器没有与配置中定义的匹配的存储引擎。我在Carrierwave配置中(在初始化器中)做了一个pry并查看了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
条目。你可以从那里回溯。
我意识到这是一个稍微陈旧的问题,但如果你还没弄明白,我希望有所帮助。