我正在尝试使用 Carrierwave 在 Sinatra 中创建一个简单的图像上传器类。我使用了与此几乎相同的代码并在 Gemfile 中指定了相同的行,但是在运行 $bundle install 并且所有安装都没有问题之后,我从以下代码中得到一个 LoadError:
宝石文件:
source 'https://rubygems.org'
ruby '1.9.3'
gem 'sinatra'
gem 'sinatra-contrib'
gem 'rack'
gem 'thin'
gem "mongo_mapper"
gem 'bson_ext'
# Image uploading to S3
gem "fog", "~> 1.3.1"
gem 'carrierwave'
gem 'rmagick', '2.13.2', :git=>'http://github.com/rmagick/rmagick.git', :require=>'RMagick'
CarrierWave 配置文件:
# Configure Carrierwave Uploads to Amazon S3
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => '(never mind about this)', # required
:aws_secret_access_key => '(or this)' # required
#:region => 'eu-west-1', # optional, defaults to 'us-east-1'
#:host => 's3.example.com', # optional, defaults to nil
#:endpoint => 'https://s3.example.com:8080' # optional, defaults to nil
}
config.fog_directory = 'penumbra-images' # required
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
end
ImageUploader 类定义:
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
process :resize_to_fit => [1024, 1024]
storage :fog
end
我的结果:
$ ruby app.rb
CarrierWave::Uploader::Base
/Users/duncanmalashock/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:124:in `require': cannot load such file -- RMagick (LoadError)
from /Users/duncanmalashock/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:124:in `require'
from /Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/gems/carrierwave-0.9.0/lib/carrierwave/processing/rmagick.rb:67:in `rescue in block in <module:RMagick>'
from /Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/gems/carrierwave-0.9.0/lib/carrierwave/processing/rmagick.rb:64:in `block in <module:RMagick>'
from /Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-3.2.14/lib/active_support/concern.rb:121:in `class_eval'
from /Users/duncanmalashock/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-3.2.14/lib/active_support/concern.rb:121:in `append_features'
from /Users/duncanmalashock/Generator/init/uploader.rb:2:in `include'
from /Users/duncanmalashock/Generator/init/uploader.rb:2:in `<class:ImageUploader>'
from /Users/duncanmalashock/Generator/init/uploader.rb:1:in `<top (required)>'
from /Users/duncanmalashock/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:124:in `require'
from /Users/duncanmalashock/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:124:in `require'
from app.rb:7:in `<main>'
任何人都可以帮忙吗?非常感谢。