I hope it helps someone.
ruby '2.6.5' rails '6.0.0'
I am making an original application.
The production environment uses Heroku. After deploying to Heroku and checking the operation, an error log appeared.
I thought that the cause was that the path to the image changed from the error log in the production environment.
If it is local, it will be displayed as it is if you put it directly under assets / images / In the production environment, it was precompiled and not displayed, so an error occurred.
When I look it up In `production, Rails puts the precompiled files in public / assets. The precompiled file is treated as a static asset by the web server. Files placed in app / assets will never be used as-is in a production environment. ``
Click here for reference articles
Make a path for the production environment by referring to the above article.
_medicine.html.erb
<%= image_tag asset_path('medicine3.jpeg'), class:"med-pic" %>
I respecified the path in this way, but in my case I got an error again.
Please point out that asset precompile is not set in the production environment.
Change before
production.rb
config.assets.compile = false
After change
production.rb
config.assets.compile = true
When I enabled this, I was able to display the image safely.
<< For beginners >> If the image is not displayed in the production environment, there is no loss in trying it
29
config.assets.compile = true
% rails assets:precompile
<%= image_tag asset_path('medicine3.jpeg'), class:"med-pic" %>
It might be better to take a quick look at what asset precompile is doing!
Recommended Posts