How to store hash in session in Ruby
I'm开发者_运维知识库 looking for a way to serialize a hash so it can be stored in a Sinatra flash session. Does anyone have any idea? Thanks.
Serialize your Hash to a JSON or YAML string and store that. This assumes that you don't have anything crazy in your Hash like a lambda or a Thread that cannot be serialized.
Might want to read this for ideas:
http://www.skorks.com/2010/04/serializing-and-deserializing-objects-with-ruby/
Personally, I use json for most of my client-facing objects that come from ruby.
精彩评论