Suppose I have a User < ActiveRecord::Base.
Now, suppose I would like to create a user instance, validate it and store it in the session if I can not save it.
user = User.new
...
session[:new_user] = user unless user.save
...
Using the ActiveRecord session one might end up with no marshal_dump is defined for class Proc coming from Marshal.dump.
Now, what is the best way to resolve such serialization errors (locate the "invalid" Proc objects) for an object (does not have to be AR in general) ?
Usually it's better to store the user id in the session, not the User instance itself. This does mean you have to do a db (or memcache) lookup for authenticated requests, but it saves you a ton of headaches around serialization/caching that you'd otherwise have to deal with.
Also, it's not an "invalid" Proc in some sense. Proc instances are containers for Ruby code and application state and therefore cannot be serialized, ever.
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