我正在使用Carrierwave在S3上存储文件,并且代码本身运行良好,但是当我运行rspec时,它将引发/usr/local/rvm/gems/ruby-2.3.1/gems/carrierwave-0.11.2/lib/carrierwave.rb:14:in
configure':未初始化的常量CarrierWave :: Uploader(NameError)`错误和因此,由于它运行测试套件,因此我的构建过程也随之崩溃。
有什么想法可能是我的问题吗?
我的uploaders/attachment_uploader.rb
文件:
# encoding: utf-8
class AttachmentUploader < 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
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# # For Rails 3.1+ asset pipeline compatibility:
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
#
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files:
# version :thumb do
# process :resize_to_fit => [50, 50]
# end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
# def extension_white_list
# %w(jpg jpeg gif png)
# end
# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
end
我的lib/carrierwave/storage/fog.rb
文件:
CarrierWave.configure do |config|
config.fog_provider = 'fog/aws' # required
config.fog_credentials = {
provider: 'AWS', # required
aws_access_key_id: ENV["AWS_ACCESS_KEY"], # required unless using use_iam_profile
aws_secret_access_key: ENV["AWS_SECRET_KEY"], # required unless using use_iam_profile
use_iam_profile: true, # optional, defaults to false
region: 'us-east-1', # optional, defaults to 'us-east-1'
host: ENV["AWS_CLOUDFRONT_HOST"], # optional, defaults to nil
endpoint: ENV["AWS_ENDPOINT"] # optional, defaults to nil
}
config.fog_directory = ENV["AWS_BUCKET"] # required
config.fog_public = false # optional, defaults to true
config.fog_attributes = { cache_control: "public, max-age=#{365.days.to_i}" } # optional, defaults to {}
end
Stacktrace:
/usr/local/rvm/gems/ruby-2.3.1/gems/carrierwave-0.11.2/lib/carrierwave.rb:14:in `configure': uninitialized constant CarrierWave::Uploader (NameError)
from /www/lib/carrierwave/storage/fog.rb:3:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.1/gems/carrierwave-0.11.2/lib/carrierwave/storage.rb:11:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.1/gems/carrierwave-0.11.2/lib/carrierwave.rb:78:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/bundler/runtime.rb:81:in `require'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/bundler/runtime.rb:81:in `block (2 levels) in require'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/bundler/runtime.rb:76:in `each'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/bundler/runtime.rb:76:in `block in require'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/bundler/runtime.rb:65:in `each'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/bundler/runtime.rb:65:in `require'
from /usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/bundler.rb:114:in `require'
from /www/config/application.rb:8:in `<top (required)>'
from /www/config/environment.rb:2:in `require'
from /www/config/environment.rb:2:in `<top (required)>'
from /www/spec/rails_helper.rb:4:in `require'
from /www/spec/rails_helper.rb:4:in `<top (required)>'
from /www/spec/controllers/application_controller_spec.rb:1:in `require'
from /www/spec/controllers/application_controller_spec.rb:1:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.1/gems/rspec-core-3.4.3/lib/rspec/core/configuration.rb:1361:in `load'
from /usr/local/rvm/gems/ruby-2.3.1/gems/rspec-core-3.4.3/lib/rspec/core/configuration.rb:1361:in `block in load_spec_files'
from /usr/local/rvm/gems/ruby-2.3.1/gems/rspec-core-3.4.3/lib/rspec/core/configuration.rb:1359:in `each'
from /usr/local/rvm/gems/ruby-2.3.1/gems/rspec-core-3.4.3/lib/rspec/core/configuration.rb:1359:in `load_spec_files'
from /usr/local/rvm/gems/ruby-2.3.1/gems/rspec-core-3.4.3/lib/rspec/core/runner.rb:106:in `setup'
from /usr/local/rvm/gems/ruby-2.3.1/gems/rspec-core-3.4.3/lib/rspec/core/runner.rb:92:in `run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/rspec-core-3.4.3/lib/rspec/core/runner.rb:78:in `run'
from /usr/local/rvm/gems/ruby-2.3.1/gems/rspec-core-3.4.3/lib/rspec/core/runner.rb:45:in `invoke'
from /usr/local/rvm/gems/ruby-2.3.1/gems/rspec-core-3.4.3/exe/rspec:4:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.1/bin/rspec:23:in `load'
from /usr/local/rvm/gems/ruby-2.3.1/bin/rspec:23:in `<main>'
from /usr/local/rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
from /usr/local/rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'