Not a bug. A cookie is just a string. You can turn anything into a
string and store it in a cookie. Something very simple like the
following might work for you:
array_for_cookie = [1,4,5,7]
cookies[:foo] = array_for_cookie .to_s
array_from_cookie = cookies[:foo][1..-2].split('','')
(And if you are just storing a single integer in a cookie be sure to
turn it into a string before setting it and then back to an integer
when you read it.)
Lou''s method allows for additional complexity by creating a type of
"cookie manager" which creates many cookies in the user''s
browser but
lets you access them as if they were one cookie object with
attributes. It''s a slight-of-hand that works well for many
people''s
needs.
If neither of those work for you, I would suggest that you consider
using sessions. A session is just a simple cookie which references a
more complex object stored on the server (which can contain hashes,
arrays and even objects). The disadvantage of sessions is that they
take up space on your server. You''ll want to decide how to manage
them depending on the needs of your application--periodically
deleting old sessions (using cron) or storing sessions in a database
are two frequent techniques.
HTH,
Kevin Skoglund
> Surely there is an other way?? If not is this then not just a bug?
>
> Lou Vanek 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"]
>