Rails heroku无效配置选项

时间:2015-10-16 15:17:40

标签: ruby-on-rails heroku

当我部署到heroku并运行@for (var c = 0; c < Model.ExistingTeams.Count; c++) { @Html.DropDownListFor(x => x.ExistingTeams[c].Captain, Model.ExistingTeams[c].MemberSelectList, new { @class = "form-control "}) } 时,我收到错误:

heroku run rake db:migrate

配置/初始化/ aws.rb

ArgumentError: invalid configuration option `:aws_access_key_id'

配置/初始化/ carrierwave.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 / aws.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 问题。但是,当我运行invalid configuration option时,它已被错误Missing required arguments: aws_access_key_id, aws_secret_access_key替换。

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

2 个答案:

答案 0 :(得分:2)

创建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

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

  

默认凭据将从以下内容自动加载   位置:

     
      
  • ENV ['AWS_ACCESS_KEY_ID']和ENV ['AWS_SECRET_ACCESS_KEY']
  •   

答案 1 :(得分:0)

我按照此页http://lifesforlearning.com/uploading-images-with-carrierwave-to-s3-on-rails/

中的步骤操作

而不是PictureUploaded我在app / uploads / picture_uploader.rb中使用了ImageUploader而不是carrier_wave.rb或carrierwave.rb我在s3.rb中设置了环境变量。在进行这些更改后,它对我有用。