NameError:生产中未初始化的常量CarrierWave :: Storage :: Fog

时间:2018-10-18 13:16:33

标签: ruby-on-rails heroku carrierwave

我仅在Heroku上出现生产错误(我没有在本地启动服务器的问题,并且相同的代码在较旧的环境(即Rails 4)下也可以工作)

NameError: uninitialized constant CarrierWave::Storage::Fog

这个问题似乎已经在很多场合被发现,但是到目前为止我所采取的各种行动都没有解决问题

https://github.com/carrierwaveuploader/carrierwave/issues/2023

我已经执行以下操作:

添加在carrierwave.rb初始化程序的顶部

require 'carrierwave/storage/fog'

已添加到carrierwave.rb初始化程序中

config.storage = :fog

由于问题似乎只在生产中发生,所以我更改了所有生产线

storage = :fog 

了解我在开发/测试中所拥有的

storage = :file

查看错误是否继续并且是否继续。我没有其他选择了。会有人提供一些技巧来帮助我解决此问题吗?我在下面添加了两个关键文件(如果我完全注释掉了服务器启动的所有内容):

carrierwave.rb

require 'carrierwave/storage/fog'

CarrierWave.configure do |config|

config.fog_credentials = {
provider:               'AWS',
aws_access_key_id:      ENV['S3_KEY'],
aws_secret_access_key:  ENV['S3_SECRET'],
region: 'us-east-1'

}

if Rails.env.test? || Rails.env.cucumber?
  CarrierWave.configure do |config|
  config.storage           = :file
  config.enable_processing = false
end
end

config.cache_dir        = "#{Rails.root}/tmp/uploads"
config.fog_directory    = ENV['S3_BUCKET_NAME']

end

Doc_uploader.rb

class DocUploader < CarrierWave::Uploader::Base

if Rails.env.development? || Rails.env.test?
storage :file
else
storage :fog

end

def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end


end

heroku日志的提取

2018-10-18T13:08:37.404979+00:00 app[web.1]: [4] Puma starting in cluster mode...
2018-10-18T13:08:37.405004+00:00 app[web.1]: [4] * Version 3.12.0 (ruby 2.4.4-p296), codename: Llamas in Pajamas
2018-10-18T13:08:37.405006+00:00 app[web.1]: [4] * Min threads: 5, max threads: 5
2018-10-18T13:08:37.405007+00:00 app[web.1]: [4] * Environment: production
2018-10-18T13:08:37.405011+00:00 app[web.1]: [4] * Process workers: 2
2018-10-18T13:08:37.405034+00:00 app[web.1]: [4] * Preloading application
2018-10-18T13:08:44.984627+00:00 app[web.1]: [4] ! Unable to load application: NameError: uninitialized constant CarrierWave::Storage::Fog
2018-10-18T13:08:44.984844+00:00 app[web.1]: bundler: failed to load command: puma (/app/vendor/bundle/ruby/2.4.0/bin/puma)
2018-10-18T13:08:44.985001+00:00 app[web.1]: NameError: uninitialized constant CarrierWave::Storage::Fog

0 个答案:

没有答案