[英]can't dump anonymous class #<Module -error on caching in rails 3
我得到無法轉儲匿名類錯誤。
我的模型中有以下方法。
def seating_for(active)
ln = cache(col("lu", active)) do
self.seat_list_for(active).where(seat_id: self.seat_entries)
end
def seat_list_for(active)
ex_id = Exc.id_by_symbol(active)
self.row.exe.seats.where(ex_id: exc_id).first.seat_alloc_mem
end
我正在嘗試緩存ln。 我收到了一個錯誤。 無法弄清楚是什么問題。
can't dump anonymous class #<Module:0x00000007ab6088>
/home/#/.rvm/gems/ruby-2.0.0-p0@anon-ui/gems/activesupport-3.2.14/lib/active_support/cache.rb:561:in `dump'
/home/#/.rvm/gems/ruby-2.0.0-p0@anon-ui/gems/activesupport-3.2.14/lib/active_support/cache.rb:561:in `initialize'
/home/#/.rvm/gems/ruby-2.0.0-p0@anon-ui/gems/redis-activesupport-3.2.4/lib/active_support/cache/redis_store.rb:34:in `new'
/home/#/.rvm/gems/ruby-2.0.0-p0@anon-ui/gems/redis-activesupport-3.2.4/lib/active_support/cache/redis_store.rb:34:in `block in write'
/home/#/.rvm/gems/ruby-2.0.0-p0@anon-ui/gems/activesupport-3.2.14/lib/active_support/cache.rb:520:in `instrument'
/home/#/.rvm/gems/ruby-2.0.0-p0@anon-ui/gems/redis-activesupport-3.2.4/lib/active_support/cache/redis_store.rb:33:in `write'
/home/#/.rvm/gems/ruby-2.0.0-p0@anon-ui/gems/activesupport-3.2.14/lib/active_support/cache.rb:299:in `fetch'
/home/#/user/projects/app/#/lib/lib_utility.rb:15:in `cache'
/home/#/user/projects/app/#/app/models/smthng.rb:566:in `seating_for'
LIB / lib_utility.rb
module LibUtility
module ClassMethods
def col(p, l)
//smthng
end
def cache(l, options={}, &b)
Rails.cache.fetch(l, expires_in: 50.minutes, &b)
end
end
def self.included(receiver)
receiver.extend ClassMethods
end
end
需要指導??
問題是您嘗試緩存ActiveRecord
關系集合。 這是不可能的。 如果要緩存查詢,則需要先將其設為數組
def seating_for(active)
cache(col("lu", active)) do
self.seat_list_for(active).where(seat_id: self.seat_entries).to_a
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.