Rails Carrierwave url is zero unless request is repeated
I have a carrier / active recording issue in my rails application. My problem is that the following code resolves all images to null
<% Ad.all.limit(30).each do |ad| %>
<img src="<%= ad.carrier_image.url %>" >
<% end %>
Where as below all images are just fine
<% Ad.all.limit(30).each do |ad| %>
<img src="<%= Ad.find(ad.id).carrier_image.url %>" >
<% end %>
We have URLs, only in the initial loop, the carrier statement does not seem to be preloaded into the active record objects. I think this is a problem with my understanding of rail congestion, but I am having a hard time figuring out how this problem could be avoided
+3
source to share
1 answer
What happens when you use the rails image_tag helper? You are also missing the parentheses from the url call as per the carrier documentation, but I don't think that's what is causing you drama.
<%= image_tag ad.carrier_image_url() %>
As a side note, you must actually move "Ad.all.limit (30)" out of its view if you want to keep all the "rails".
0
source to share