【发布时间】:2012-12-11 09:18:55
【问题描述】:
我的控制器中有这样的动作:
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
【问题讨论】:
-
请贴出相关模型:User、Posting、Category。
-
我已添加有问题的相关模型
标签: ruby-on-rails memcached rails-engines dalli