gpt4 book ai didi

ruby-on-rails - Rails heroku 无效配置选项

转载 作者:行者123 更新时间:2023-12-04 05:34:07 26 4
gpt4 key购买 nike

当我部署到 heroku 并运行 heroku run rake db:migrate 时,我收到错误:

ArgumentError: invalid configuration option `:aws_access_key_id'

配置/初始化程序/aws.rb

if Rails.env.production?
S3Client = Aws::S3::Client.new(
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
aws_region: 'us-east-1'
)
end

config/initializers/carrierwave.rb

if Rails.env.production?
CarrierWave.configure do |config|
config.fog_credentials = {
provider: 'AWS',
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
region: 'us-east-1'
}
config.fog_directory = ENV['S3_BUCKET']
end
end

为什么我会收到“无效的配置选项”错误?

编辑

新的 config/initializers/carrierwave.rb 文件:

if Rails.env.production?
CarrierWave.configure do |config|
config.fog_credentials = {
provider: 'AWS',
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
region: 'us-east-1',
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
aws_region: 'us-east-1'
}
config.fog_directory = ENV['S3_BUCKET']
#config.fog_attributes = {:signature_version => :v4}
end
end

config/initializers/aws.rb 现在是空的。

这修复了无效的配置选项问题。但是,当我运行 RAILS_ENV=production bundle exec rake assets:precompile 时,它已被错误替换为 Missing required arguments: aws_access_key_id, aws_secret_access_key

更令人困惑的是,在上述更改后,我设法成功运行了一次 RAILS_ENV=production bundle exec rake assets:precompile,但它突然停止工作了。

最佳答案

创建 Aws::S3::Client 时的选项不以 aws_ 开头。那将是愚蠢的。

if Rails.env.production?
S3Client = Aws::S3::Client.new(
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
region: 'us-east-1'
)
end

但是您实际上不需要传递凭据选项:

Default credentials are loaded automatically from the following locations:

  • ENV['AWS_ACCESS_KEY_ID'] and ENV['AWS_SECRET_ACCESS_KEY']

关于ruby-on-rails - Rails heroku 无效配置选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33173982/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com