Closed
Description
I have the following code to get some entries from contentful:
@professionals = Web::Dentist.all.params({'order' => 'fields.orden', 'locale' => I18n.locale}).load.items
each entry has a relation to an asset (picture), so I'm accessing it like:
- professionals.each do |dentist|
= dentist.picture.url
It works without any problem and if you inspect each picture you'll see:
<Web::Dentist[dentist] id='496kcSEqCkAuaGiC8as2a8'>
[<Contentful::Asset id='51sOKzSr7iCAoygq6206ES' url='//images.ctfassets.net/0lo6jhr35aeg/51sOKzSr7iCAoygq6206ES/c4c73b51ed40248e9d5f8b2d3bdcab85/DR.Bedoya-web.jpg'>]
but if I try to cache the response like this:
@professionals = Rails.cache.fetch(:"professionals_#{I18n.locale}", expires_in: ENV['cache_ttl'].to_i) do
Web::Dentist.all.params({'order' => 'fields.orden', 'locale' => I18n.locale}).load.items
end
and then iterate the entries, only the first item has the relation as Contentful::Asset, the rest of items have Contenful::Link, if you inspect each entry you'll see:
<Web::Dentist[dentist] id='496kcSEqCkAuaGiC8as2a8'>
[<Contentful::Link id='51sOKzSr7iCAoygq6206ES'>]
So it throws an error, again it only happens when you cache the response, I'm using memcached for it.
Metadata
Metadata
Assignees
Labels
No labels