質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Q&A

解決済

1回答

1793閲覧

Ruby on Rails チュートリアル13章 herokuデプロイ時に環境変数が無いと起きるエラー

my2_630

総合スコア13

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

0グッド

0クリップ

投稿2019/04/10 11:20

編集2019/04/12 21:51

前提・実現したいこと

現在、Rails tutorial 13章の最後で躓いています。

テストは全て通っており、ローカル環境だと画像投稿も成功しています。

しかし、herokuでデプロイする時に下記のエラーが発生します。

発生している問題・エラーメッセージ

AccessキーとSecretキーが渡されていないとエラーメッセージが出されます。

-----> Ruby app detected -----> Compiling Ruby/Rails -----> Using Ruby version: ruby-2.6.0 -----> Installing dependencies using bundler 1.15.2 Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment Warning: the running version of Bundler (1.17.2) is older than the version that created the lockfile (1.17.3). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`. The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`. Fetching gem metadata from https://rubygems.org/......... Using rake 12.3.2 (略) Post-install message from fog: ------------------------------ Thank you for installing fog! IMPORTANT NOTICE: If there's a metagem available for your cloud provider, e.g. `fog-aws`, you should be using it instead of requiring the full fog collection to avoid unnecessary dependencies. 'fog' should be required explicitly only if: - The provider you use doesn't yet have a metagem available. - You require Ruby 1.9.3 support. ------------------------------ Removing bundler (1.15.2) Removing autoprefixer-rails (9.5.0) Removing sass (3.7.3) Removing minitest (5.10.3) Removing rack (2.0.6) Bundle completed (39.90s) Cleaning up the bundler cache. Warning: the running version of Bundler (1.17.2) is older than the version that created the lockfile (1.17.3). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`. The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`. -----> Installing node-v10.14.1-linux-x64 -----> Detecting rake tasks -----> Preparing app for Rails asset pipeline Running: rake assets:precompile rake aborted! ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/fog-core-1.45.0/lib/fog/core/service.rb:244:in `validate_options' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/fog-core-1.45.0/lib/fog/core/service.rb:268:in `handle_settings' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/fog-core-1.45.0/lib/fog/core/service.rb:98:in `new' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/fog-core-1.45.0/lib/fog/core/services_mixin.rb:16:in `new' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/fog-core-1.45.0/lib/fog/storage.rb:27:in `new' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/carrierwave-1.2.2/lib/carrierwave/uploader/configuration.rb:124:in `eager_load_fog' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/carrierwave-1.2.2/lib/carrierwave/uploader/configuration.rb:137:in `fog_credentials=' /tmp/build_33683b461f648aad077409566a3b7c1f/config/initializers/carrier_wave.rb:3:in `block in <top (required)>' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/carrierwave-1.2.2/lib/carrierwave/uploader/configuration.rb:159:in `configure' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/carrierwave-1.2.2/lib/carrierwave.rb:14:in `configure' /tmp/build_33683b461f648aad077409566a3b7c1f/config/initializers/carrier_wave.rb:2:in `<top (required)>' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:286:in `load' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:286:in `block in load' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:258:in `load_dependency' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:286:in `load' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/engine.rb:655:in `block in load_config_initializer' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/activesupport-5.1.6/lib/active_support/notifications.rb:168:in `instrument' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/engine.rb:654:in `load_config_initializer' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/engine.rb:612:in `block (2 levels) in <class:Engine>' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/engine.rb:611:in `each' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/engine.rb:611:in `block in <class:Engine>' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `instance_exec' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `run' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/initializable.rb:59:in `block in run_initializers' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/initializable.rb:48:in `each' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/initializable.rb:48:in `tsort_each_child' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/initializable.rb:58:in `run_initializers' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/application.rb:353:in `initialize!' /tmp/build_33683b461f648aad077409566a3b7c1f/config/environment.rb:5:in `<top (required)>' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/application.rb:329:in `require' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/application.rb:329:in `require_environment!' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/railties-5.1.6/lib/rails/application.rb:445:in `block in run_tasks_blocks' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define' /tmp/build_33683b461f648aad077409566a3b7c1f/vendor/bundle/ruby/2.6.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>' Tasks: TOP => environment (See full trace by running task with --trace) ! ! Precompiling assets failed. ! ! Push rejected, failed to compile Ruby app. ! Push failed

該当のソースコード

gemfile

1 2group :production do 3 gem 'pg', '0.20.0' 4 gem 'fog-aws' 5end 6 7# Windows環境ではtzinfo-dataというgemを含める必要があります 8gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
if Rails.env.production? CarrierWave.configure do |config| config.fog_provider = 'fog/aws' config.fog_credentials = { # Amazon S3用の設定 :provider => 'AWS', :region => ENV['S3_REGION'], # 例: 'ap-northeast-1' :aws_access_key_id => ENV['S3_ACCESS_KEY'], :aws_secret_access_key => ENV['S3_SECRET_KEY'] } config.fog_directory = ENV['S3_BUCKET'] end end
class PictureUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick process resize_to_limit: [400, 400] if Rails.env.production? storage :fog else storage :file end # アップロードファイルの保存先ディレクトリは上書き可能 # 下記はデフォルトの保存先 def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end # アップロード可能な拡張子のリスト def extension_whitelist %w(jpg jpeg gif png) end end

試したこと

https://qiita.com/nobu0717/items/4425c02157bc5e88d7b6

https://qiita.com/nobu0717/items/a34a896f6e7ad68dc54e

上記のURLを参考に、IAMユーザーを作成、環境変数を設定しました。

heroku config コマンドやherokuのダッシュボードから環境変数が正常に渡されていることは確認出来ています。

その他、様々な記事を参考にさせていただきましたが、未解決のままです。

皆様のお力を頂けると幸いです、よろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

コードを修正して
git push してなかったのが原因でした...。

投稿2019/04/12 21:54

my2_630

総合スコア13

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問