Is Rails cookies method in view and controller diffrent?


#1

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


#2

removed_email_address@domain.invalid 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 W.


#3

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.


#4

Michael W. wrote:

removed_email_address@domain.invalid 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 W.

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.