ruby-on-rails - 无法转储匿名类 #<Module - rails 3 中的缓存错误

标签 ruby-on-rails ruby ruby-on-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

关于ruby-on-rails - 无法转储匿名类 #<Module - rails 3 中的缓存错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19288142/

相关文章:

ruby-on-rails - Rails 中如何抑制回溯?

ruby-on-rails - after_create 回调似乎无法正常工作

ruby-on-rails - Ruby on Rails - 部分使用集合循环时出现问题

ruby-on-rails - 如何使用带有 simple_form 的 country_select gem 列出选择中的所有国家/地区

ruby - 将 Ruby 数组重组为哈希

ruby-on-rails - rails : has_many through not returning correctly with namespaced models

ruby-on-rails - Rails schema & migrate 不断恢复到 VERSION=0

mysql - Rails ActiveRecord::Relation 未定义方法

ruby-on-rails - 新遗物不断记录 'Starting Agent shutdown' 这是正常的还是配置错误

ruby-on-rails - 重启后载波复位