Reputation: 59
The situation is one where there is no issue in Development, but in Production ( with assets pre-compiled ) an image is not found in the asset pipeline.
I feel like I'm missing something subtle, but after reading documentation and searching on this site I cannot pin point the reason for the issue.
snippet from .html.erb view file:
<div class="media-left">
<figure class="image is-256x256">
<%= image_tag('95090365.jpeg') %>
</figure>
</div>
The precompiled image is in /public/assets :-
95090365-8976ee2cb59e500cd649fb288749282959ada00f93955c319300e4d85779d687.jpg
When I try to load the relevant view, I get a 500 error on the page, and see this in log/production.log :
I, [2020-03-16T05:11:48.841878 #1] INFO -- : [d802e301-bbe2-4881-83ba-8e107adaa04e] Rendering users/show.html.erb within layouts/application
I, [2020-03-16T05:11:48.842593 #1] INFO -- : [d802e301-bbe2-4881-83ba-8e107adaa04e] Rendered users/show.html.erb within layouts/application (Duration: 0.6ms | Allocations: 406)
I, [2020-03-16T05:11:48.842735 #1] INFO -- : [d802e301-bbe2-4881-83ba-8e107adaa04e] Completed 500 Internal Server Error in 5ms (ActiveRecord: 0.4ms | Allocations: 1785)
F, [2020-03-16T05:11:48.843367 #1] FATAL -- : [d802e301-bbe2-4881-83ba-8e107adaa04e]
[d802e301-bbe2-4881-83ba-8e107adaa04e] ActionView::Template::Error (The asset "95090365.jpeg" is not present in the asset pipeline.):
[d802e301-bbe2-4881-83ba-8e107adaa04e] 7: <article class="media">
[d802e301-bbe2-4881-83ba-8e107adaa04e] 8: <div class="media-left">
[d802e301-bbe2-4881-83ba-8e107adaa04e] 9: <figure class="image is-256x256">
[d802e301-bbe2-4881-83ba-8e107adaa04e] 10: <%= image_tag('95090365.jpeg') %>
[d802e301-bbe2-4881-83ba-8e107adaa04e] 11: </figure>
[d802e301-bbe2-4881-83ba-8e107adaa04e] 12: </div>
[d802e301-bbe2-4881-83ba-8e107adaa04e] 13: <div class="media-content">
[d802e301-bbe2-4881-83ba-8e107adaa04e]
I noticed on some other questions and answers, that people have set
config.assets.compile = true
to fix this error, but I see in the Rails documentation that is isnt recommended for Production
This mode uses more memory, performs more poorly than the default, and is not recommended" - https://guides.rubyonrails.org/asset_pipeline.html
I've tried the image_tag with the jpeg suffix and without, and same issue with both.
Any ideas ? Thanks in advance.
Upvotes: 0
Views: 1269
Reputation: 59
<%= image_tag('95090365.jpeg') %>
needed to change to
<%= image_tag('95090365.jpg') %>
Upvotes: 2