`
dazuiba
  • 浏览: 128066 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

如何解决 singleton can't be dumped

阅读更多
问题描述:
一场堆栈如下
TypeError (singleton can't be dumped):
    D:/dev/InstantRails/ruby/lib/ruby/1.8/pstore.rb:349:in `dump'
    D:/dev/InstantRails/ruby/lib/ruby/1.8/pstore.rb:349:in `dump'
    D:/dev/InstantRails/ruby/lib/ruby/1.8/pstore.rb:330:in `transaction'
    D:/dev/InstantRails/ruby/lib/ruby/1.8/cgi/session/pstore.rb:81:in `update'
    D:/dev/InstantRails/ruby/lib/ruby/1.8/cgi/session/pstore.rb:88:in `close'
    D:/dev/InstantRails/ruby/lib/ruby/1.8/cgi/session.rb:324:in `close'
    D:/dev/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/base.rb:1190:in `close_session'
    D:/dev/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/base.rb:1234:in `process_cleanup_without_flash
    D:/dev/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/flash.rb:146:in `process_cleanup_without_filte
    D:/dev/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/filters.rb:761:in `process_cleanup_without_ses


该问题的原因是,一些singleton对象不能放到session中。这里的singleton对象指的是没有办法store 或者persistent的对象,比如:上传的文件,这个对这个对象进行persistent是没有意义的,因为该文件所指向的文件源在网络上、在浏览器所在的机器上。
  注意,有两种方式会引发这个异常,1、你将一个singleton对象直接放到session中 2、你放到session的对象引用了一个singleton对象。
比如,你将People类的一个事例,放到了session中,该类中引入了一个module ImageSystem,该module专门处理文件上传的。不巧的是,该module的设计者将一个临时文件 tempfile当成了一个instance 变量,于是异常一定会产生。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics