Can store array or hash in cookies?


#1

Hi

According to rdoc: value - the cookie’s value or list of values (as an
array).

So, I can use arrays, briliant.
But… It does not work (at least on webrick)

I wrote a controller:

def check_cookies_first
cookies[:chef] =
{:value => [“first”, “second”], :expires => Time.local
(2020)}

    render_text ":)"

end

def check_cookies_second
begin
render_text "cookies class is: " + cookies[:chef].class.to_s

  • "
    value: " + cookies[:chef]
    rescue Exception => e
    render_text "Why this don’t work? exception: " + e.to_s
    end
    end

Started server:

get check_cookies_first —> “:)”
get check_cookies_second —> “cookies class is: String value: first”

What is wrong? Is it a webrick issue?

Thanks a lot,
Szczepan


#2

if you add this method,

 def cookie(name)
   @cookies[name.to_s].value if @cookies[name.to_s] && 

@cookies[name.to_s].respond_to?(:value)
end

to the CookieJar class in the cookies.rb file
you would be able to access the entire cookie array.

cookies.cookie(:chef)

=> [“first”, “second”]


#3

Surely there is an other way?? If not is this then not just a bug?

Lou V. wrote:

if you add this method,

 def cookie(name)
   @cookies[name.to_s].value if @cookies[name.to_s] && 

@cookies[name.to_s].respond_to?(:value)
end

to the CookieJar class in the cookies.rb file
you would be able to access the entire cookie array.

cookies.cookie(:chef)

=> [“first”, “second”]