Forum: Ruby on Rails is Rails cookies method in view and controller diffrent?

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.
00b40e1c586cf8b5e353b2a8a9999116?d=identicon&s=25 Guest (Guest)
on 2007-03-28 12:26
rails 1.2.3


code :
in controller:

cookies[:test] = 1
@cookies = cookies



in view:

<%=@cookies[:test].class.to_s%>
<%=cookies[:text].class.to_s%>


output:
String Array
Dfd6f9989147955682701da8227df8b4?d=identicon&s=25 Michael Wang (Guest)
on 2007-03-28 12:31
(Received via mailing list)
rails-mailing-list@andreas-s.net wrote:
>
> in view:
>
> <%=@cookies[:test].class.to_s%>
> <%=cookies[:text].class.to_s%>
>
>
> output:
> String Array

Did you type that in wrong? You have two different key names there.


--
Michael Wang
00b40e1c586cf8b5e353b2a8a9999116?d=identicon&s=25 Guest (Guest)
on 2007-03-28 12:51
Guest wrote:
> rails 1.2.3
>
>
> code :
> in controller:
>
> cookies[:test] = 1
> @cookies = cookies
>
>
>
> in view:
>
> <%=@cookies[:test].class.to_s%>
> <%=cookies[:text].class.to_s%>
>
>
> output:
> String Array

sorry , type wrong


the cookies in view is a Hash
the cookies in controller is a ActionController::CookieJar


now , how to use cookies in the view?
thank you.
00b40e1c586cf8b5e353b2a8a9999116?d=identicon&s=25 Guest (Guest)
on 2007-03-28 12:57
Michael Wang wrote:
> rails-mailing-list@andreas-s.net wrote:
>>
>> in view:
>>
>> <%=@cookies[:test].class.to_s%>
>> <%=cookies[:text].class.to_s%>
>>
>>
>> output:
>> String Array
>
> Did you type that in wrong? You have two different key names there.
>
>
> --
> Michael Wang

thank you .
your name looks like a chinese , and i'm too.
nice to meet you.

i was resolved this issure:

in controllers/application.rb

add a class method

helper_method :cookies

the cookies method in view will work correct.
This topic is locked and can not be replied to.