[RUBY] How to solve the problem that the website image is not displayed after deploying to heroku on Rails 5

I solved the problem that the image was not loaded after deploying to Heroku with my own web service, so I will introduce the method.

environment

・ Rails 5.2.2

・ Ruby 2.5.3

・ Amazon Web Service

・ Windows 10

problem

Website images don't load after deploying to Heroku

What you want to achieve

I want to display an image of a web page

procedure

① Open the production.rb file in config / environments

Modify the code in the production.rb file.

Before correction

production.rb


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

Revised

production.rb


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

The entire code in the modified production.rb

production.rb


Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # Code is not reloaded between requests.
  config.cache_classes = true

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both threaded web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.
  config.eager_load = true

  # Full error reports are disabled and caching is turned on.
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
  # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
  # config.require_master_key = true

  # Disable serving static files from the `/public` folder by default since
  # Apache or NGINX already handles this.
  config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier
  # config.assets.css_compressor = :sass

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

  # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = 'http://assets.example.com'

  # Specifies the header that your server uses for sending files.
  # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

  # Store uploaded files on the local file system (see config/storage.yml for options)
  config.active_storage.service = :local

  # Mount Action Cable outside main process or domain
  # config.action_cable.mount_path = nil
  # config.action_cable.url = 'wss://example.com/cable'
  # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  # config.force_ssl = true

  # Use the lowest log level to ensure availability of diagnostic information
  # when problems arise.
  config.log_level = :debug

  # Prepend all log lines with the following tags.
  config.log_tags = [ :request_id ]

  # Use a different cache store in production.
  # config.cache_store = :mem_cache_store

  # Use a real queuing backend for Active Job (and separate queues per environment)
  # config.active_job.queue_adapter     = :resque
  # config.active_job.queue_name_prefix = "scheduleapplication_#{Rails.env}"

  config.action_mailer.perform_caching = false

  # Ignore bad email addresses and do not raise email delivery errors.
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
  # config.action_mailer.raise_delivery_errors = false

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation cannot be found).
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners.
  config.active_support.deprecation = :notify

  # Use default logging formatter so that PID and timestamp are not suppressed.
  config.log_formatter = ::Logger::Formatter.new

  # Use a different logger for distributed setups.
  # require 'syslog/logger'
  # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

  if ENV["RAILS_LOG_TO_STDOUT"].present?
    logger           = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger    = ActiveSupport::TaggedLogging.new(logger)
  end

  # Do not dump schema after migrations.
  config.active_record.dump_schema_after_migration = false
end

Reference site / article

Asset Pipeline Rails Guide Version 6.0 ・ [Summary of settings related to Rails4 asset pipeline](https://qiita.com/tomomomo1217/items/fa8dfa094cc4c0e4e350#%E5%8F%82%E8%80%83%E3%82%B5%E3%82%A4%E3 % 83% 88)

Recommended Posts

How to solve the problem that the website image is not displayed after deploying to heroku on Rails 5
About the problem that the image is not displayed after AWS deployment
[Rails] How to solve the problem that the default image is overwritten when editing without uploading the image [Active Storage]
How the website is displayed on the screen
How to solve the problem when the value is not sent when the form is disabled in rails and sent
How to solve the problem that you can not pull image from docker hub with Minikube
How to solve the problem that notification cannot be requested on iOS14
[Rails] About the error that the image is not displayed in the production environment
How to solve the problem that it is not processed normally when nesting beans in Spring Batch
[Heroku] How to solve when an error is displayed on git push heroku master
Solved the problem that profile and logout were not displayed on the screen after signup.
[Ruby on rails] When executing the heroku command, bash: heroku: command not found is displayed. [Rails tutorial]
I want to solve the problem that JS is not displayed properly unless reloaded when transitioning with Turbolinks: link_to
How to fix the problem that Aptana Studio does not start
[Rails / Heroku / MySQL] How to reset the DB of Rails application on Heroku
[Rails carrier wave] How to not transition to the error screen even if the image upload is not selected
[Rails] How to temporarily save the request URL of a user who is not logged in and return to that URL after logging in
What to do if the background image is not applied after deployment
How to solve the local environment construction of Ruby on Rails (MAC)!
[Cloud9] Yay! You ’re on Rails! Is not displayed in the rails tutorial
[Rails] How to solve the time lag of created_at after save method
[Rails MySQL] How to reset DB on heroku
How to resolve errors that occur in the "Ruby on Rails" integration test
[Error] How to resolve the event that the screen does not transition after editing
[Rails] What to do when the Refile image is not displayed when writing the processing at the time of Routing Error
What to do if the update does not take effect after deploying Rails AWS
[Rails] About the problem that the video thumbnail automatically created by FFmpeg is not displayed [AWS S3 + EC2 + CarrierWave + Fog]
How to remove the underline displayed by Rails link_to
[Ruby on Rails] How to change the column name
[Ruby On Rails] How to reset DB in Heroku
Solve the N + 1 problem with Ruby on Rails: acts-as-taggable-on
How to fix the problem that the upper half is cut off when using UITabBar
[Rails] How to display an image in the view
Address to the problem that the video is paused during background transition while playing video on iOS14
Use cryptographically secure pseudo-random numbers to verify that the solution to the Monty Hall problem is not 50%
[Rails] The problem that pry-byebug does not stop through breakpoints
[Rails] Solving the problem that session timeout does not work
[Note] About the Fizz_Buzz problem (How Ruby on Rails works)
How to run React and Rails on the same server
How to check the database of apps deployed on Heroku
How to deploy on heroku
[Rails] fields_for is not displayed
Problem investigation that JST is converted to +0000 +0000 when golang timezone conversion is performed on Alpine docker image
How to make an application with ruby on rails (assuming that the environment has been built)
About the solution to the problem that the log of logback is not output when the web application is stopped
I tried to understand how the rails method "redirect_to" is defined
[Rails] How to put a crown mark on the ranking function
I tried to understand how the rails method "link_to" is defined
How to identify the path that is easy to make a mistake
How to write the view when Vue is introduced in Rails?
Lenovo ThinkPad T14 Gen1 How to solve the problem that the speaker becomes dummy and cannot be used when installing Ubuntu 20.04 on AMD
How to deploy jQuery on Rails
How to use Ruby on Rails
How to deploy Bootstrap on Rails
Rails on Tiles (how to write)
Deploy Rails on Docker to heroku
How to interact with a server that does not crash the app
The problem that the contents of params are completely displayed in the [Rails] view
About the problem that the server can not be started with rails s
[Must-see for beginners] rails_12factor is not required to publish Rails app to Heroku
[Docker] How to solve the error function not implemented @ io_fread ~ [Super easy]