🖥

Ruby on Rails – local で RAILS_ENV=production でサーバーを起動してもつながらない場合 (コンソー

に公開

解決

production環境では画面にもコンソールにもエラーが出力されていないのがデフォルトのようだ。これが理由だった。

環境変数を指定してコンソールにログを出力することで解決した。
これで単にルーティングエラーが起きていることが分かるようになった。

RAILS_LOG_TO_STDOUT=1 RAILS_ENV=production rails server

コンソール出力の例

RAILS_LOG_TO_STDOUT=1 RAILS_ENV=production rails server
=> Booting Puma
=> Rails 7.0.4.2 application starting in production
=> Run `bin/rails server --help` for more startup options
W, [2023-02-06T22:12:58.122114 #44354]  WARN -- : You are running SQLite in production, this is generally not recommended. You can disable this warning by setting "config.active_record.sqlite3_production_warning=false".
Puma starting in single mode...
* Puma version: 5.6.5 (ruby 3.1.2-p20) ("Birdie's Version")
*  Min threads: 5
*  Max threads: 5
*  Environment: production
*          PID: 44354
* Listening on http://0.0.0.0:3000
Use Ctrl-C to stop
I, [2023-02-06T22:13:00.524139 #44354]  INFO -- : [ad3808c3-b91b-41ba-9cb1-39c08562f558] Started GET "/" for 127.0.0.1 at 2023-02-06 22:13:00 +0900
F, [2023-02-06T22:13:00.525240 #44354] FATAL -- : [ad3808c3-b91b-41ba-9cb1-39c08562f558]
[ad3808c3-b91b-41ba-9cb1-39c08562f558] ActionController::RoutingError (No route matches [GET] "/"):
[ad3808c3-b91b-41ba-9cb1-39c08562f558]

ブラウザのエラー画面表示

configでブラウザにもエラー画面を表示するように出来る

config/environments/production.rb

  config.consider_all_requests_local       = true

もちろん本当のproduction環境では設定すべきではないので動作テストにだけ利用すること

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2023-02-06

Discussion