How can I serialize an array or an object and then save it into a cookie?
cookies[:mydata] = serialize({
:key1 => 'tralala',
:key2 => 'hahaha'
})
Thx!
How can I serialize an array or an object and then save it into a cookie?
cookies[:mydata] = serialize({
:key1 => 'tralala',
:key2 => 'hahaha'
})
Thx!
Initial object:
my_object = {:k1 => 'v1', :k2 => 'v2'}
Saving:
cookies[:my_data] = {
:value => Marshal.dump(my_object),
:expires => 4.years.from_now
}
Reading:
my_object = Marshal.load(cookies[:my_data])