trivektor
trivektor

Reputation: 5638

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.

Upvotes: 2

Views: 2733

Answers (2)

Glenn
Glenn

Reputation: 5342

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.

Upvotes: 1

Phrogz
Phrogz

Reputation: 303271

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.

Upvotes: 4

Related Questions