rails6 「ActionView::Template::Error (The asset “application.css” is not present in the asset pipeline」の対処法

rails6 「ActionView::Template::Error (The asset “application.css” is not present in the asset pipeline」の対処法

rails6でデプロイ時にエラー「ActionView::Template::Error (The asset “application.css” is not present in the asset pipeline」が発生した場合の対処法を記述してます。

環境

  • OS CentOS Linux release 7.9.2009 (Core)
  • Ruby 2.7.2
  • Rails 6.1.1
  • rbenv 1.1.2-40-g62d7798

エラー全文

アクセス時に発生。ログは、「log/production.log」より確認。

I, [2021-01-13T15:38:48.325735 #16044]  INFO -- : [df275f56-b23f-48a2-8e26-cf621d908062] Started GET "/" for xxx.xxx.xxx.xxx at 2021-01-13 15:38:48 +0900
I, [2021-01-13T15:38:48.327290 #16044]  INFO -- : [df275f56-b23f-48a2-8e26-cf621d908062] Processing by TopController#index as HTML
I, [2021-01-13T15:38:48.341334 #16044]  INFO -- : [df275f56-b23f-48a2-8e26-cf621d908062]   Rendered top/index.html.erb within layouts/application (Duration: 0.4ms | Allocations: 90)
I, [2021-01-13T15:38:48.342505 #16044]  INFO -- : [df275f56-b23f-48a2-8e26-cf621d908062]   Rendered layout layouts/application.html.erb (Duration: 1.6ms | Allocations: 584)
I, [2021-01-13T15:38:48.342707 #16044]  INFO -- : [df275f56-b23f-48a2-8e26-cf621d908062] Completed 500 Internal Server Error in 15ms (Allocations: 2460)
F, [2021-01-13T15:38:48.343592 #16044] FATAL -- : [df275f56-b23f-48a2-8e26-cf621d908062]   
[df275f56-b23f-48a2-8e26-cf621d908062] ActionView::Template::Error (The asset "application.css" is not present in the asset pipeline.

対処法

プリコンパイル処理を実行します。

rails tmp:cache:clear
rails assets:precompile

または、config配下の「production.rb」を、以下通りに変更する

  #config.assets.compile = false
  config.assets.compile = true

再起動

rails s -e production