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

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

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

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

Q&A

1回答

630閲覧

railssでの本番環境でのエラーについて

tan1

総合スコア1

Ruby on Rails 5

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

1グッド

1クリップ

投稿2022/09/01 10:33

railsでサイトを製作中です。

http://localhost:3000/
でローカルでのサイトの立ち上げはできます。
ちゃんとサイトの画面が表示されています。

しかしheroku open
した時、本番環境では

Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command
heroku logs --tail

というエラーが画面に出ます。
heroku logs --tailでログを確認したときのものが下記です。

heroku run condoleしてもなぜかログが出てこず
irb(main):001:0>
と出てくるので調べようがありません。

2022-09-01T10:11:14.147283+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/loader.rb:239:in `block (2 levels) in eager_load' 2022-09-01T10:11:14.147285+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/loader/helpers.rb:41:in `block in ls' 2022-09-01T10:11:14.147293+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/loader/helpers.rb:27:in `each' 2022-09-01T10:11:14.147294+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/loader/helpers.rb:27:in `ls' 2022-09-01T10:11:14.147302+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/loader.rb:234:in `block in eager_load' 2022-09-01T10:11:14.147303+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/loader.rb:219:in `synchronize' 2022-09-01T10:11:14.147310+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/loader.rb:219:in `eager_load' 2022-09-01T10:11:14.147311+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/loader.rb:318:in `each' 2022-09-01T10:11:14.147318+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/loader.rb:318:in `eager_load_all' 2022-09-01T10:11:14.147319+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/railties-6.1.6.1/lib/rails/application/finisher.rb:133:in `block in <module:Finisher>' 2022-09-01T10:11:14.147320+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/railties-6.1.6.1/lib/rails/initializable.rb:32:in `instance_exec' 2022-09-01T10:11:14.147328+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/railties-6.1.6.1/lib/rails/initializable.rb:32:in `run' 2022-09-01T10:11:14.147329+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/railties-6.1.6.1/lib/rails/initializable.rb:61:in `block in run_initializers' 2022-09-01T10:11:14.147337+00:00 app[web.1]: from /app/vendor/ruby-3.1.2/lib/ruby/3.1.0/tsort.rb:228:in `block in tsort_each' 2022-09-01T10:11:14.147337+00:00 app[web.1]: from /app/vendor/ruby-3.1.2/lib/ruby/3.1.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component' 2022-09-01T10:11:14.147339+00:00 app[web.1]: from /app/vendor/ruby-3.1.2/lib/ruby/3.1.0/tsort.rb:431:in `each_strongly_connected_component_from' 2022-09-01T10:11:14.147347+00:00 app[web.1]: from /app/vendor/ruby-3.1.2/lib/ruby/3.1.0/tsort.rb:349:in `block in each_strongly_connected_component' 2022-09-01T10:11:14.147348+00:00 app[web.1]: from /app/vendor/ruby-3.1.2/lib/ruby/3.1.0/tsort.rb:347:in `each' 2022-09-01T10:11:14.147350+00:00 app[web.1]: from /app/vendor/ruby-3.1.2/lib/ruby/3.1.0/tsort.rb:347:in `call' 2022-09-01T10:11:14.147357+00:00 app[web.1]: from /app/vendor/ruby-3.1.2/lib/ruby/3.1.0/tsort.rb:347:in `each_strongly_connected_component' 2022-09-01T10:11:14.147358+00:00 app[web.1]: from /app/vendor/ruby-3.1.2/lib/ruby/3.1.0/tsort.rb:226:in `tsort_each' 2022-09-01T10:11:14.147366+00:00 app[web.1]: from /app/vendor/ruby-3.1.2/lib/ruby/3.1.0/tsort.rb:205:in `tsort_each' 2022-09-01T10:11:14.147366+00:00 app[web.1]: from
shinoharat👍を押しています

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

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

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

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

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

tan1

2022/09/01 10:34

/app/vendor/bundle/ruby/3.1.0/gems/railties-6.1.6.1/lib/rails/initializable.rb:60:in `run_initializers' 2022-09-01T10:11:14.147368+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/railties-6.1.6.1/lib/rails/application.rb:391:in `initialize!' 2022-09-01T10:11:14.147377+00:00 app[web.1]: from /app/config/environment.rb:5:in `<main>' 2022-09-01T10:11:14.147377+00:00 app[web.1]: from config.ru:3:in `require_relative' 2022-09-01T10:11:14.147379+00:00 app[web.1]: from config.ru:3:in `block in <main>' 2022-09-01T10:11:14.147387+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/rack-2.2.4/lib/rack/builder.rb:116:in `eval' 2022-09-01T10:11:14.147387+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/rack-2.2.4/lib/rack/builder.rb:116:in `new_from_string' 2022-09-01T10:11:14.147395+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/rack-2.2.4/lib/rack/builder.rb:105:in `load_file' 2022-09-01T10:11:14.147396+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/rack-2.2.4/lib/rack/builder.rb:66:in `parse_file' 2022-09-01T10:11:14.147404+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/rack-2.2.4/lib/rack/server.rb:349:in `build_app_and_options_from_config' 2022-09-01T10:11:14.147404+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/rack-2.2.4/lib/rack/server.rb:249:in `app' 2022-09-01T10:11:14.147412+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/rack-2.2.4/lib/rack/server.rb:422:in `wrapped_app' 2022-09-01T10:11:14.147413+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/rack-2.2.4/lib/rack/server.rb:312:in `block in start' 2022-09-01T10:11:14.147414+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/rack-2.2.4/lib/rack/server.rb:379:in `handle_profiling' 2022-09-01T10:11:14.147422+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/rack-2.2.4/lib/rack/server.rb:311:in `start' 2022-09-01T10:11:14.147422+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/railties-6.1.6.1/lib/rails/commands/server/server_command.rb:39:in `start' 2022-09-01T10:11:14.147430+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/railties-6.1.6.1/lib/rails/commands/server/server_command.rb:144:in `block in perform' 2022-09-01T10:11:14.147431+00:00 app[web.1]: from <internal:kernel>:90:in `tap' 2022-09-01T10:11:14.147438+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/railties-6.1.6.1/lib/rails/commands/server/server_command.rb:135:in `perform' 2022-09-01T10:11:14.147439+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run' 2022-09-01T10:11:14.147441+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command' 2022-09-01T10:11:14.147448+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch' 2022-09-01T10:11:14.147449+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/railties-6.1.6.1/lib/rails/command/base.rb:69:in `perform' 2022-09-01T10:11:14.147456+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/railties-6.1.6.1/lib/rails/command.rb:48:in `invoke' 2022-09-01T10:11:14.147457+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/railties-6.1.6.1/lib/rails/commands.rb:18:in `<main>' 2022-09-01T10:11:14.147459+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' 2022-09-01T10:11:14.147466+00:00 app[web.1]: from /app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require' 2022-09-01T10:11:14.147467+00:00 app[web.1]: from bin/rails:5:in `<main>' 2022-09-01T10:11:14.311498+00:00 heroku[web.1]: Process exited with status 1 2022-09-01T10:11:14.375343+00:00 heroku[web.1]: State changed from starting to crashed 2022-09-01T10:11:46.000000+00:00 app[api]: Build started by user 2022-09-01T10:13:07.246086+00:00 app[api]: Deploy ff220467 by user 2022-09-01T10:13:07.246086+00:00 app[api]: Release v10 created by user 2022-09-01T10:13:07.449920+00:00 heroku[web.1]: State changed from crashed to starting 2022-09-01T10:13:12.000000+00:00 app[api]: Build succeeded 2022-09-01T10:13:13.876465+00:00 heroku[web.1]: Starting process with command `bin/rails server -p ${PORT:-5000} -e production` 2022-09-01T10:13:17.289180+00:00 app[web.1]: => Booting Puma 2022-09-01T10:13:17.289195+00:00 app[web.1]: => Rails 6.1.6.1 application starting in production 2022-09-01T10:13:17.289195+00:00 app[web.1]: => Run `bin/rails server --help` for more startup options 2022-09-01T10:13:18.629332+00:00 app[web.1]: Puma starting in single mode... 2022-09-01T10:13:18.629346+00:00 app[web.1]: * Version 3.12.6 (ruby 3.1.2-p20), codename: Llamas in Pajamas 2022-09-01T10:16:37.814850+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=stark-temple-03312.herokuapp.com request_id=f3c40702-7c75-4141-ab85-83e2e6b98747 fwd="126.95.114.152" dyno= connect= service= status=503 bytes= protocol=https 2022-09-01T10:20:52.737376+00:00 app[web.1]: => Booting Puma 2022-09-01T10:20:52.737420+00:00 app[web.1]: => Rails 6.1.6.1 application starting in production 2022-09-01T10:20:52.737421+00:00 app[web.1]: => Run `bin/rails server --help` for more startup options 2022-09-01T10:20:53.776022+00:00 app[web.1]: Puma starting in single mode... 2022-09-01T10:20:53.776041+00:00 app[web.1]: * Version 3.12.6 (ruby 3.1.2-p20), codename: Llamas in Pajamas 2022-09-01T10:20:53.776042+00:00 app[web.1]: * Min threads: 5, max threads: 5 2022-09-01T10:20:53.776042+00:00 app[web.1]: * Environment: production 2022-09-01T10:20:53.776043+00:00 app[web.1]: * Daemonizing... 2022-09-01T10:20:53.915415+00:00 heroku[web.1]: Process exited with status 0 2022-09-01T10:20:54.015332+00:00 heroku[web.1]: State changed from starting to crashed 2022-09-01T10:20:54.023379+00:00 heroku[web.1]: State changed from crashed to starting 2022-09-01T10:21:00.526483+00:00 heroku[web.1]: Starting process with command `bin/rails server -p ${PORT:-5000} -e production` 2022-09-01T10:21:03.516825+00:00 app[web.1]: => Booting Puma 2022-09-01T10:21:03.516842+00:00 app[web.1]: => Rails 6.1.6.1 application starting in production 2022-09-01T10:21:03.516843+00:00 app[web.1]: => Run `bin/rails server --help` for more startup options 2022-09-01T10:21:04.600300+00:00 app[web.1]: Puma starting in single mode... 2022-09-01T10:21:04.600347+00:00 app[web.1]: * Version 3.12.6 (ruby 3.1.2-p20), codename: Llamas in Pajamas 2022-09-01T10:21:04.600348+00:00 app[web.1]: * Min threads: 5, max threads: 5 2022-09-01T10:21:04.600348+00:00 app[web.1]: * Environment: production 2022-09-01T10:21:04.600349+00:00 app[web.1]: * Daemonizing... 2022-09-01T10:21:04.803779+00:00 heroku[web.1]: Process exited with status 0 2022-09-01T10:21:04.866435+00:00 heroku[web.1]: State changed from starting to crashed 2022-09-01T10:21:07.247663+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=stark-temple-03312.herokuapp.com request_id=d4b9a993-4d48-4582-b845-b00f9b48c278 fwd="126.95.114.152" dyno= connect= service= status=503 bytes= protocol=https 2022-09-01T10:21:07.566710+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=stark-temple-03312.herokuapp.com request_id=7a3570a9-2ef9-49af-aa0f-8ecfec95fd6f fwd="126.95.114.152" dyno= connect= service= status=503 bytes= protocol=https ログの続きです。
guest

回答1

0

zeitwerk でエラーが出ているので、ファイル名とクラス名が一致していない可能性が高いと思います。

例えば、
app/models/user.rb には User というクラス(またはモジュール)を定義する必要がありますし、
app/models/x/y/z.rb には X::Y::Z というクラス(またはモジュール)が必要です。

以下のコマンドで、ファイル名とクラス名が一致していないものを検出できます。
試してみてください。

bin/rails zeitwerk:check

--

ローカルでのサイトの立ち上げはできます。

しかしheroku open した時、本番環境では
・・・
というエラーが画面に出ます。

開発環境では動作に必要な最低限のファイルしか読み込まないので、おかしなファイルが紛れていても、それを使わなければエラーになりません。

一方、本番環境ではすべてのファイルを事前に読み込むため、一つでもおかしなファイルがあればエラーになります。

投稿2022/09/02 04:20

shinoharat

総合スコア1676

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問