问题
I'm doing chapter 11 of hartle's tutorial.
When I ran heroku run rake db:migrate
I got this error:
Missing required arguments: aws_access_key_id, aws_secret_access_key
I solved it with the answer in enter link description here and migrate successfully.but now when I run
bundle exec rake test
It gives me:
rake aborted!
ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key
This is my carrierwave file:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => ENV['S3_KEY'],
:aws_secret_access_key => ENV['S3_SECRET'],
:region => ENV['S3_REGION'],
:endpoint => ENV['S3_ENDPOINT']
}
if Rails.env.test? || Rails.env.development?
config.storage = :file
config.enable_processing = false
config.root = "#{Rails.root}/tmp/uploads/#{DateTime.now.to_f}.#{rand(999)}.#{rand(999)}"
else
config.storage = :fog
end
config.cache_dir = "#{Rails.root}/tmp/uploads/#{DateTime.now.to_f}.#{rand(999)}.#{rand(999)}"
config.fog_directory = ENV['S3_BUCKET_NAME']
config.fog_public = false
config.fog_attributes = {}
end
I tested the answer in enter link description here and it didn't work for me.
回答1:
I would set these in the test helper:
ENV['S3_KEY'] = 'S3_KEY'
ENV['S3_SECRET'] = 'S3_SECRET'
ENV['S3_REGION'] = 'S3_REGION'
ENV['S3_ENDPOINT'] = 'S3_ENDPOINT'
Alternately, you can do
if ! Rails.env.test?
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => ENV['S3_KEY'],
:aws_secret_access_key => ENV['S3_SECRET'],
:region => ENV['S3_REGION'],
:endpoint => ENV['S3_ENDPOINT']
}
end
But I think the first is better because it does not pollute your production code with test code.
来源:https://stackoverflow.com/questions/29973162/missing-required-arguments-aws-access-key-id-aws-secret-access-key-on-rake-tes