LoginSignup
0

More than 1 year has passed since last update.

【Rails】本番環境でCSSで指定した背景画像が表示されない。。。の解消

Posted at

環境

Rails 6.1.4

やりたいこと

ローカルで正常に表示されていた背景画像が本番環境で表示されなかったことの解消

結論

SCSSファイル内の記述を次のように書き換えデプロイすることで正常に表示。

app/assets/stylesheets/〇〇.scss
//修正前
background-image: url('bg-image.jpg');

//修正後
background-image: image-url('bg-image.jpg');

なぜ起こったのか?

アセットパイプラインのキャッシュの高速化と『digest』という仕組みが関係している。
上記によって、デプロイ後のapp/assets以下のファイルは全てpublic/assetsに上記のdigest付きになって移動され、参照できなくなったことにより発生したもの。

参考記事

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0