ruby - Rails Carrierwave url is nil unless queried again -


i having issue carrierwave/active-record in rails application. problem following code resolves of images null

<% ad.all.limit(30).each |ad| %>     <img src="<%= ad.carrier_image.url %>" > <% end %> 

where following renders images fine

<% ad.all.limit(30).each |ad| %>     <img src="<%= ad.find(ad.id).carrier_image.url %>" > <% end %> 

the urls there, on initial loop carrier_image not seem preloaded active record objects think issue understanding of rails eager loading, having trouble figuring out how 1 avoid issue

what happens when use rails image_tag helper? you're missing brackets off url call per carrierwave documentation, don't think that's what's causing drama.

 <%= image_tag ad.carrier_image_url() %> 

as side note, should move "ad.all.limit(30)" out of view if wish keep "railsy".


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -