我正在尝试在Rails应用程序中使用以下代码在 session 中存储值
session[:key] = value
我得到以下错误
TypeError (no _dump_data is defined for class Proc):
activesupport (3.2.9) lib/active_support/message_verifier.rb:53:in `dump'
activesupport (3.2.9) lib/active_support/message_verifier.rb:53:in `generate'
actionpack (3.2.9) lib/action_dispatch/middleware/cookies.rb:300:in `[]='
actionpack (3.2.9) lib/action_dispatch/middleware/session/cookie_store.rb:67:in `set_cookie'
rack (1.4.1) lib/rack/session/abstract/id.rb:330:in `commit_session'
rack (1.4.1) lib/rack/session/abstract/id.rb:206:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.9) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `
任何帮助都将受到高度赞赏。
最佳答案
您的value
是Proc或在其内部嵌套了某个Proc。由于Procs和Lambda是封闭的,因此无法序列化/编码(marshal)处理/转储。闭包取决于创建它们时内存中的内容,因此以后无法正确反序列化。
参见this answer。
我不确定我将要做什么,看来我将不得不找出一种无需依靠Procs即可完成任务的方法。