Forum: Ruby on Rails can store array or hash in cookies?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
16319aba44da117ca73484d1ce32227b?d=identicon&s=25 Szczepan Faber (szczepiq)
on 2006-01-07 17:21
(Received via mailing list)
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
Ce60c4f78a63b0695e4dafc4bd7964f7?d=identicon&s=25 Lou Vanek (Guest)
on 2006-01-08 16:27
(Received via mailing list)
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"]
2101d75ccd71c5dfb984991a7ba53b9b?d=identicon&s=25 harm (Guest)
on 2006-02-19 16:59
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"]
This topic is locked and can not be replied to.