我正在使用带有 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]