未初始化的常量CarrierWave

未初始化的常量CarrierWave

本文介绍了NameError:未初始化的常量CarrierWave :: Storage :: Fog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了在stackoverflow和github上给出的几种解决方案,但是找不到解决方案.我在我的应用程序中使用了 carrierwave(0.10.0) fog-aws(0.8.1)宝石将图像上传到S3.

I have tried several solution given on stackoverflow and github, but couldnt find the solution. I am using carrierwave (0.10.0) and fog-aws (0.8.1) gems for my app to upload image to S3.

NameError: uninitialized constant CarrierWave::Storage::Fog
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:73:in `eval'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:73:in `eval'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:73:in `storage'
from /home/pulkit/dev/roid/rails/appbrowzer/app/uploaders/publisher_action_icon_uploader.rb:11:in `<class:PublisherActionIconUploader>'
from /home/pulkit/dev/roid/rails/appbrowzer/app/uploaders/publisher_action_icon_uploader.rb:3:in `<top (required)>'
from /home/pulkit/dev/roid/rails/appbrowzer/app/models/manage_channel_action.rb:3:in `<class:ManageChannelAction>'
from /home/pulkit/dev/roid/rails/appbrowzer/app/models/manage_channel_action.rb:1:in `<top (required)>'
from (irb):1
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/console.rb:110:in `start'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/console.rb:9:in `start'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:68:in `console'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:9:in `require'
from bin/rails:9:in `<main>'

当我尝试使用 fog(1.37.0)宝石而不是 fog-aws 宝石时,我得到了不同的错误.

And when i tried using the fog(1.37.0) gem instead of the fog-aws gem, then i am getting the different error.

ArgumentError:  is not a recognized provider
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/fog-core-1.35.0/lib/fog/core/services_mixin.rb:12:in `new'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/fog-core-1.35.0/lib/fog/storage.rb:27:in `new'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/storage/fog.rb:102:in `connection'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/storage/fog.rb:356:in `connection'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/storage/fog.rb:368:in `directory'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/storage/fog.rb:261:in `store'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/storage/fog.rb:80:in `store!'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/store.rb:59:in `block in store!'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/callbacks.rb:17:in `with_callbacks'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/store.rb:58:in `store!'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/mount.rb:375:in `store!'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/carrierwave-0.10.0/lib/carrierwave/mount.rb:207:in `store_icon!'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:432:in `block in make_lambda'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:228:in `block in halting_and_conditional'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:506:in `block in call'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:506:in `each'
... 10 levels...
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:220:in `transaction'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:348:in `with_transaction_returning_status'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:286:in `block in save'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:301:in `rollback_active_record_state!'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/transactions.rb:285:in `save'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/persistence.rb:34:in `create'
    from (irb):1
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/console.rb:110:in `start'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/console.rb:9:in `start'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /home/pulkit/.rvm/gems/ruby-2.3.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:9:in `require'
    from bin/rails:9:in `<main>'2.3.0 :002 >

推荐答案

通过在我的Gemfile中添加雾宝石来解决此问题

Fixed the issue by adding Fog gem in my Gemfile

gem 'fog', require: 'fog/aws'

lib/carrierwave/storage/fog.rb 中删除了配置文件.rel ="nofollow">起雾的宝石,并将载波配置放在 config/initializers/carrierwave.rb

Removed the configuration file from lib/carrierwave/storage/fog.rb as mentioned for fog-aws gem and placed the carrierwave configuration in config/initializers/carrierwave.rb

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',
    :aws_access_key_id      => 'XYZ',
    :aws_secret_access_key  => 'ABC',
    :region                 => 'region'
  }
  config.fog_directory  = 'bucket_name'
end

这篇关于NameError:未初始化的常量CarrierWave :: Storage :: Fog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 17:44