我的控制器中有这样的动作:
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