0

したがって、このエラーが発生しました: NameError: uninitialized constant which StackOverflow は、意図せずにアップグレードしていることを意味しますが、それはできません。私のバージョンは最高であるため、宝石ファイルに持っています: gem "aws-sdk-s3", require:間違い

初期化ファイルと関係があるのでしょうか?これは、ビルド ログで問題が発生した場所です。

Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       NameError: uninitialized constant AWS
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:80:in `block in load_missing_constant'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:9:in `without_bootsnap_cache'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:80:in `rescue in load_missing_constant'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:59:in `load_missing_constant'
       /tmp/build_381cfb05_/config/initializers/aws.rb:1:in `<main>'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in `load'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in `load'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:666:in `block in load_config_initializer'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/notifications.rb:182:in `instrument'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:665:in `load_config_initializer'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:625:in `block (2 levels) in <class:Engine>'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:624:in `each'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:624:in `block in <class:Engine>'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:32:in `instance_exec'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:32:in `run'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:61:in `block in run_initializers'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:50:in `each'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:50:in `tsort_each_child'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:60:in `run_initializers'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/application.rb:363:in `initialize!'
       /tmp/build_381cfb05_/config/environment.rb:5:in `<main>'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.4.0/lib/zeitwerk/kernel.rb:34:in `require'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/application.rb:339:in `require_environment!'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/application.rb:523:in `block in run_tasks_blocks'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
       
       Caused by:
       NameError: uninitialized constant AWS
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:61:in `block in load_missing_constant'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:17:in `allow_bootsnap_retry'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/active_support.rb:60:in `load_missing_constant'
       /tmp/build_381cfb05_/config/initializers/aws.rb:1:in `<main>'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in `load'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:55:in `load'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:666:in `block in load_config_initializer'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.3.2/lib/active_support/notifications.rb:182:in `instrument'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:665:in `load_config_initializer'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:625:in `block (2 levels) in <class:Engine>'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:624:in `each'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/engine.rb:624:in `block in <class:Engine>'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:32:in `instance_exec'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:32:in `run'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:61:in `block in run_initializers'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:50:in `each'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:50:in `tsort_each_child'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/initializable.rb:60:in `run_initializers'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/application.rb:363:in `initialize!'
       /tmp/build_381cfb05_/config/environment.rb:5:in `<main>'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.4.0/lib/zeitwerk/kernel.rb:34:in `require'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/application.rb:339:in `require_environment!'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.2/lib/rails/application.rb:523:in `block in run_tasks_blocks'
       /tmp/build_381cfb05_/vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
       Tasks: TOP => environment
       (See full trace by running task with --trace)
 !
 !     Precompiling assets failed.
 !
 !     Push rejected, failed to compile Ruby app.
 !     Push failed

これは aws.rb ファイルです。

AWS::S3::Base.establish_connection!(
    :access_key_id   => ENV['S3_KEY:'],
    :secret_access_key => ENV['S3_SECRET']
   )
   

これは Heroku 側です: ここに画像の説明を入力してください

画像の埋め込みはまだ許可されていないので、リンクのみです。

さて、aws.rb ファイルを次のように変更しました。

require 'aws-sdk'
AWS::S3::Base.establish_connection!(
    :access_key_id   => ENV['S3_KEY:'],
    :secret_access_key => ENV['S3_SECRET']
   )
   

そして、これを得ました:

 Running: rake assets:precompile
       rake aborted!
       LoadError: cannot load such file -- aws-sdk

AWS gem を次のように変更しました: gem 'aws-sdk'

代わりに、ビルドログの失敗から次の出力を取得しました。

Running: rake assets:precompile
       rake aborted!
       NameError: uninitialized constant AWS

これは私の storage.yml ファイルの一部です:

# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
amazon:
   service: S3
   #access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
  # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
   region: us-east-1
   bucket: agrifood.bucket

aws.rb 初期化ファイルをコメントアウトし、storage.yml を以下のように変更した後:

# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
amazon:
   service: S3
   #access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
   #access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id  => ENV['S3_KEY:']) %>
   access_key_id: ENV['S3_KEY:'])
   secret_access_key: ENV['S3_SECRET'])
   #secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key => ENV['S3_SECRET']) %>
   #secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
   #region: us-east-1
   region: eu-west-1
   bucket: agrifood.bucket

Active Storage ビルド パックを追加すると、次のようになりました。

###### WARNING:
       We detected that some binary dependencies required to
       use all the preview features of Active Storage are not
       present on this system.
       
       For more information please see:
         https://devcenter.heroku.com/articles/active-storage-on-heroku

ごく最近、storage.yml を次のように変更しました。

amazon:
   service: S3
   #access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
   #access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id  => ENV['S3_KEY:']) %>
   access_key_id: ENV['S3_KEY:'])
   secret_access_key: ENV['S3_SECRET'])
   #secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key => ENV['S3_SECRET']) %>
   #secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
   #region: us-east-1
   #region: eu-west-1
   region: ENV['AWS_BUCKET_REGION'])
   bucket: agrifood.bucket
'''
Which still gave me this:

警告: Rails 構成の検出に失敗しました HEROKU_DEBUG_RAILS_RUNNER=1 をデバッグに設定します

警告:
   We detected that some binary dependencies required to
   use all the preview features of Active Storage are not
   present on this system.

I then changed it to this:

Aws.config.update({ リージョン: 'eu-west-1', 認証情報: Aws::Credentials.new(ENV['S3_KEY:'], ENV['S3_SECRET']), })

S3_BUCKET = Aws::S3::Resource.new.bucket(ENV['S3_BUCKET'])


As per the advice to changed AWS to Aws I did what is just above, however, that didn't fix it.
4

2 に答える 2