[RUBY] I want to display background-ground-image on heroku.

environment

ruby 2.6.5 rails 6.0.0 mysql 5.6

problem

The background image that was displayed without problems in the local environment was not displayed in the production environment (heroku).

What I tried

config/environments/production.rb


# Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = false

From

config/environments/production.rb


# Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = false

change to Reference article → https://qiita.com/__xxx/items/fa15f358beba2b9389da

However, the expected behavior did not work.

Most of the other articles tend to behave well in production with this content, but I didn't.

solution

I found a slightly old article in 2015 → https://www.cotegg.com/blog/?p=189 Try out.

① Change from css to scss

② Also change the contents of scss

main.css


.main {
  display: flex;
  background-image: url("../main-bg.png ");      /*Specify the URL of the image*/
  background-size:cover;
  background-repeat:  no-repeat;
  background-attachment: fixed;
}

From

main.scss


.main {
  display: flex;
  background-image: image-url("main-bg.png ");      /*Change the description here*/
  background-size:cover;
  background-repeat:  no-repeat;
  background-attachment: fixed;
}

change to Confirm that there are no problems in the local environment

③ Precompile

% bundle exec rake assets:precompile RAILS_ENV=production

Don't forget to commit here and push to production.

% git push heroku master

Check the behavior in the production environment.

It went well.

Recommended Posts

I want to display background-ground-image on heroku.
I want to install PHP 7.2 on Ubuntu 20.04.
I want to use NetBeans on Mac → I can use it!
I want to convert characters ...
How to deploy on heroku
I want to display the name of the poster of the comment
[Android Studio] I want to use Maven library on Android
I want to simplify the log output on Android
I want to connect to Heroku MySQL from a client
I want to use screen sharing on the login screen on Ubuntu 18
[Rails] I want to display "XX minutes ago" using created_at!
I want to put the JDK on my Mac PC
I want to narrow down the display of docker ps
I want to use FireBase to display a timeline like Twitter
I want to use FormObject well
I want to convert InputStream to String
I want to docker-compose up Next.js!
Deploy Rails on Docker to heroku
Implemented a strong API for "I want to display ~~ on the screen" with simple CQRS
I want to connect SONY headphones WH-1000XM4 with LDAC on ubuntu 20.04! !!
I want to use swipeback on a screen that uses XLPagerTabStrip
I just want to write Java using Eclipse on my Mac
I want to add the disabled option to f.radio_button depending on the condition
I want to display the images under assets/images in the production environment
I tried to display the calendar on the Eclipse console using Java.
I want to develop a web application!
How to redo a deployment on Heroku
I want to write a nice build.gradle
I want to eliminate duplicate error messages
Sample to display (head-up) notifications on Android
I want to make an ios.android app
I want to use DBViewer with Eclipse 2018-12! !!
How to publish an application on Heroku
I want to RSpec even at Jest!
I want to write a unit test!
Deploy to Heroku [Ruby on Rails] Beginner
I want to stop Java updates altogether
I tried to build AdoptOpenjdk 11 on CentOS 7
I want to use @Autowired in Servlet
I want to target static fields to @Autowired
I want to do team development remotely
Pre-processing to display on the browser (compiler)
I want to display the number of orders for today using datetime.
I want to display images with REST Controller of Java and Spring!
[Ruby] I want to display posted items in order of newest date
I want to display a PDF in Chinese (Korean) with thin reports
I want to display an error message when registering in the database
I want to test Action Cable with RSpec test
I was addicted to using RXTX on Sierra
I want to sort by tab delimited by ruby
I want to output the day of the week
Run R from Java I want to run rJava
[Ruby on Rails] How to display error messages
I want to send an email in Java.
I want to graduate from npm install properly [2020]
I want to use arrow notation in Ruby
Introducing New Relic to Rails apps on Heroku
I want to play a GIF image on the Andorid app (Java, Kotlin)
[Ruby] I want to do a method jump!
How to save images on Heroku to S3 on AWS
I want to use java8 forEach with index