Hi guys. I''m trying to do the following:
value = {:number => 1, :num_list => [1,2,3]}
cookies[:some_name] = {:value => value,
:expires => 1.day.from_now}
I''m getting the gsub error. How do I make my ''value''
hash a string and
then decode it back to its original Hash type? Any example code would
be helpful here.
thanks.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Sam,
> value = {:number => 1, :num_list => [1,2,3]}
> cookies[:some_name] = {:value => value,
> :expires => 1.day.from_now}
> I''m getting the gsub error.
I typed your code in the console (see below), and it works fine!
Typo?
Alain
>> value={:number => 1, :num_list => [1,2,3]}
=> {:num_list=>[1, 2, 3], :number=>1}>> app.cookies[:test]={:value => value, :expires => 1.day.from_now}
=> {:value=>{:num_list=>[1, 2, 3], :number=>1}, :expires=>Wed Nov
29
15:57:29 CET 2006}>> app.cookies[:test]
=> {:value=>{:num_list=>[1, 2, 3], :number=>1}, :expires=>Wed Nov
29
15:57:29 CET 2006}>> app.cookies[:test][:value].class
=> Hash
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
That looks like something that would *only* work in a test environment On 11/28/06, Alain Ravet <alain.ravet-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Sam, > > value = {:number => 1, :num_list => [1,2,3]} > > cookies[:some_name] = {:value => value, > > :expires => 1.day.from_now} > > I''m getting the gsub error. > > I typed your code in the console (see below), and it works fine! > Typo? > > Alain > > > >> value={:number => 1, :num_list => [1,2,3]} > => {:num_list=>[1, 2, 3], :number=>1} > >> app.cookies[:test]={:value => value, :expires => 1.day.from_now} > => {:value=>{:num_list=>[1, 2, 3], :number=>1}, :expires=>Wed Nov 29 > 15:57:29 CET 2006} > >> app.cookies[:test] > => {:value=>{:num_list=>[1, 2, 3], :number=>1}, :expires=>Wed Nov 29 > 15:57:29 CET 2006} > >> app.cookies[:test][:value].class > => Hash > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Guys, this is definitely not working in Rails and other people have gotten gsub errors for this. Can somebody tell me how to safely store the value into the cookie as a string and then retrieve that value back into a Hash? Thanks. On 11/28/06, Obie Fernandez <obiefernandez-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > That looks like something that would *only* work in a test environment > > On 11/28/06, Alain Ravet <alain.ravet-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Sam, > > > value = {:number => 1, :num_list => [1,2,3]} > > > cookies[:some_name] = {:value => value, > > > :expires => 1.day.from_now} > > > I''m getting the gsub error. > > > > I typed your code in the console (see below), and it works fine! > > Typo? > > > > Alain > > > > > > >> value={:number => 1, :num_list => [1,2,3]} > > => {:num_list=>[1, 2, 3], :number=>1} > > >> app.cookies[:test]={:value => value, :expires => 1.day.from_now} > > => {:value=>{:num_list=>[1, 2, 3], :number=>1}, :expires=>Wed Nov 29 > > 15:57:29 CET 2006} > > >> app.cookies[:test] > > => {:value=>{:num_list=>[1, 2, 3], :number=>1}, :expires=>Wed Nov 29 > > 15:57:29 CET 2006} > > >> app.cookies[:test][:value].class > > => Hash > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 11/29/06, Sam Donaldson <samonderous-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Guys, this is definitely not working in Rails and other people have gotten > gsub errors for this. Can somebody tell me how to safely store the value > into the cookie as a string and then retrieve that value back into a Hash?Of course it won''t work. Even if it let you set the value, when you later retrieve the cookie it''s just a string, and you can''t convert it back into a hash. Just marshal it then base64 encode it, then decode/unmarshal it when you read it back. Not that I suggest doing that, I think it''s crazy, but it will work. Chris --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---