偶尔发现不能 Marshal.dump 分页数据,这怎么回事?现在 will_paginate 和 kaminari 都返回 ActiveRecord::Relation 了
Marshal.dump Question.where(id:1)
#=> "\x04\bo:\eActiveRecord::Relation':\v.....
Marshal.dump Question.where(id:1).page(1)
#TypeError: can't dump anonymous class #<Module:0x00000003ea17f0>
# from (irb):16:in `dump'
# from (irb):16
# from /home/qiu/.rvm/gems/ruby-1.9.3-p0/gems/railties-#3.2.2/lib/rails/commands/console.rb:47:in `start'
# from /home/qiu/.rvm/gems/ruby-1.9.3-p0/gems/railties-#3.2.2/lib/rails/commands/console.rb:8:in `start'
# from /home/qiu/.rvm/gems/ruby-1.9.3-p0/gems/railties-#3.2.2/lib/rails/commands.rb:41:in `<top (required)>'
# from script/rails:6:in `require'
# from script/rails:6:in `<main>'
Marshal can't dump following objects:
anonymous Class/Module.
objects which related to its system (ex: Dir, File::Stat, IO, File, Socket and so on)
an instance of MatchData, Data, Method, UnboundMethod, Proc, Thread, ThreadGroup, Continuation
objects which defines singleton methods
def get_answers(page)
Rails.cache.fetch "test1/#{page}" do
answers.page(page)
end
end
上面的就不能用了,这怎么解决?? active_support/cache.rb @value = Marshal.dump(value)