My user.rb (model) has the following instance method:
def points_last_seven_days
last_seven_days_hash_raw = self.reports.group_by_day(series: true) { |r| r.created_at }
out = {}
last_seven_days_hash_raw.each do |day, reports|
out[day.to_s] = reports.last.bullets
end
out
end
When i run User.first.points_last_seven_days
everything goes ok, as expected i get an hash with data.
Now comes the tricky part. I have a cache module loading User into redis.
For that i use, among other things:
def make_cacheable_strings
output_array = []
get_users_for_status.each do |user|
output_array << user.to_json(methods: USER_CACHED_METHODS)
end
output_array
end
My USER_CACHED_METHODS
are as follows:
USER_CACHED_METHODS = [
...,
:points_last_seven_days
]
The point is: User.last.method_name = correct data
CachedUser["method_name"] ( json redis ) = {} // empty hash...
What is happening?
Thank you