载波直接宝石安装错误

时间:2018-10-19 11:13:27

标签: ruby-on-rails carrierwave carrierwave-direct

我为我的Rails项目有一个名为# conftest.py def pytest_collection_modifyitems(session, config, items): if config.getoption('--flake8'): items[:] = [item for item in items if item.get_marker('flake8')] 的上载程序,该上载程序可以接收一个zip文件,然后使用BulkImagesUploader将其上传到S3。一切正常,但是我发现自己必须使用carrierwave gem将文件直接从浏览器上传到S3。

我已按照gem README上的说明进行操作,但是出现错误提示

carrierwave_direct

下面是我的代码

宝石文件

/home/moiz/.rvm/gems/ruby-2.4.1/gems/fog-0.7.2/lib/fog/core/provider.rb:5:in `extended': undefined method `providers' for Fog:Module (NoMethodError)

初始化器

# Gemfile.rb

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '>= 2.4.1'

gem 'aasm', '~> 4.12'
gem 'acts-as-taggable-on', '~> 6.0'
gem 'acts_as_commentable'
gem 'ancestry'
gem 'bootsnap', '>= 1.1.0', require: false
gem 'cancancan'
gem 'carrierwave_direct'
gem 'carrierwave', '~> 1.0'
gem 'client_side_validations'
gem 'client_side_validations-simple_form'
gem 'coffee-rails', '~> 4.2'
gem 'devise'
gem 'dotenv-rails'
gem 'fog'
# gem 'fog-aws'
gem 'jbuilder', '~> 2.5'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'kaminari'
gem 'mini_magick', '>=  4.9.2'
gem 'mysql2'
gem 'paranoia', '~> 2.2'
gem 'puma', '~> 3.11'
gem 'rails', '~> 5.2.0'
gem 'ransack'
gem 'sass-rails', '~> 5.0'
gem 'sidekiq'
gem 'simple_form'
gem 'turbolinks', '~> 5'
gem 'uglifier', '>= 1.3.0'
gem 'wicked', '>= 1.3.3'

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: %i[mri mingw x64_mingw]
  gem 'factory_bot_rails'
  gem 'pry'
  gem 'rails-erd'
  gem 'rspec-rails', '~> 3.7'
  gem "switch_user"
end

group :development do
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
  gem "awesome_print", '~> 1.8.0', require: "ap"
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15', '< 4.0'
  gem 'selenium-webdriver'
  # Easy installation and use of chromedriver to run system tests with Chrome
  gem 'chromedriver-helper'
  gem 'database_cleaner'
  gem 'faker'
  gem 'guard-rspec'
  gem 'launchy'
  gem 'shoulda'
end
gem 'rubocop', require: false
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

上载器

# config/initializers/carrierwave.rb

CarrierWave.configure do |config|
  config.fog_credentials = {
    provider: 'AWS',
    aws_access_key_id: ENV['AWS_KEY'],
    aws_secret_access_key: ENV['AWS_SECRET'],
    region: ENV['AWS_REGION']
  }
  config.fog_directory = ENV['S3_BUCKET']
end

堆栈跟踪

class BulkImageUploader < CarrierWave::Uploader::Base
  include CarrierWaveDirect::Uploader
  def extension_whitelist
    %w(zip)
  end
end

此错误可能是什么原因?

1 个答案:

答案 0 :(得分:0)

我意识到错误是与Rails使用的雾版本有关。本应使用的版本是fog 2.0,但Gemfile.lock提到的是fog 0.7。

如果其他任何人遇到此错误,请检查您宝石的版本。这很可能是您出错的原因