I am trying to store a value in the session using the below code in my rails application
session[:key] = value
And i get the below error
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 `
Any help is highly appreciated.
In my case, we were caching an ActiveRecord model and that model had an @ variable that contained a lambda function. That was causing the issue.
Your value
is either a Proc or has s Proc nested inside of it somewhere. Procs and lambdas cannot be serialized/marshaled/dumped because they are closures. Closures depend on what is in memory at the time they are created, and therefore cannot be unserialized correctly later.
See this answer.
I'm not sure what I will be doing in my case, it looks like I will have to figure out a way to accomplish my task without relying on Procs.
What is this value? Is it a complicated object? An active record instance maybe?
I had the same problem trying to put an FourSquare client object into the session. I've changed to create a new instance every time, instead of recovering from session, and it worked ok.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With