问题
Hello i just added AWS S3 Bucket to my app.
Here is the app error https://dry-atoll-6663.herokuapp.com/
In heroku logs when i $heroku restart this error appears
2015-04-28T09:13:15.009823+00:00 app[web.1]: [3] ! Unable to load application: NameError: uninitialized constant CarrierWave::Storage::Fog
My Carrierwave.rb
CarrierWave.configure do |config|
config.fog_credentials = {
# Configuration for Amazon S3
:provider => 'AWS',
:aws_access_key_id => ENV['S3_ACCESS_KEY'],
:aws_secret_access_key => ENV['S3_SECRET_KEY']
}
config.fog_directory = ENV['S3_BUCKET']
end
Any ideas? Me and my friend are scratching our heads big time...
回答1:
Credit @Marcus for correctly answering this in the comments.
In your config/initializers/carrierwave.rb file, you will need to update
CarrierWave.configure do |config|
# This is the old way, and broken
config.storage = :fog
into
CarrierWave.configure do |config|
# This is the new way!
config.fog_provider = 'fog/aws'
see the carrierwave github for more information.
回答2:
After pulling my hair out for a couple hours, I finally determined that this seems to come from a recent issue with carrierwave (0.10.0)
With thanks to GitHub user trantorLiu, this is what fixed me up:
I also encountered this issue. I fixed it by specify an older Carrierwave revision in Gemfile.lock.
Here's my Gemfile.lock. Revision
37cf31ddoesn't work for me, so I rollbacked tocb1a5bf. And then everything worked as it used to be.GIT remote: git://github.com/carrierwaveuploader/carrierwave.git revision: cb1a5bfc6601a4e5d0abb6bad17911d73dcb57e3 specs: carrierwave (0.10.0) activemodel (>= 3.2.0) activesupport (>= 3.2.0) json (>= 1.7) mime-types (>= 1.16)Here's my Gemfile. FYI.
gem 'fog', require: 'fog/aws' gem 'carrierwave', github: 'carrierwaveuploader/carrierwave'
Also, if it helps, here my config/initializers/carrierwave.rb:
CarrierWave.configure do |config|
if Rails.env.development?
config.storage = :file
elsif Rails.env.test?
config.storage = :file
config.enable_processing = false
else
config.storage = :fog
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: Rails.configuration.aws.access_key_id,
aws_secret_access_key: Rails.configuration.aws.secret_access_key,
}
config.fog_directory = Rails.configuration.files.aws_bucket
end
end
回答3:
Upon further review, I decided to drop fog altogether. I ended up using carrierwave-aws. The config is practically identical.
My new config/initializers/carrierwave.rb:
CarrierWave.configure do |config|
if Rails.env.development?
config.storage = :file
elsif Rails.env.test?
config.storage = :file
config.enable_processing = false
else
config.storage = :aws
config.aws_bucket = Rails.configuration.files.aws_bucket
config.aws_acl = 'public-read'
config.aws_credentials = {
access_key_id: Rails.configuration.aws.access_key_id,
secret_access_key: Rails.configuration.aws.secret_access_key,
region: Rails.configuration.aws.region,
}
end
end
来源:https://stackoverflow.com/questions/29915571/nameerror-uninitialized-constant-carrierwavestoragefog-in-heroku-logs