私のコントローラーにはそのようなアクションがあります:
def my
@user = Ads::User.find current_user.id
@postings = Rails.cache.fetch("@user.postings.includes(:category)") do
@postings = @user.postings.includes(:category)
end
end
@postingsをキャッシュしようとすると、そのようなエラーが発生します。
Marshalling error for key '@user.postings.includes(:category)': can't dump anonymous class #<Module:0x000000048f9040>
You are trying to cache a Ruby object which cannot be serialized to memcached.
インクルードなしで@postingsをキャッシュしようとしても、エラーは発生しません。何が問題なのかわからない。
下部に関連するモデルがあります。
module Ads
class User < ::User
has_many :postings, dependent: :destroy
end
end
module Ads
class Posting < ActiveRecord::Base
belongs_to :user, counter_cache: true
belongs_to :category
end
end
module Ads
class Category < ActiveRecord::Base
has_many :postings, dependent: :destroy
end
end