Simple eRuby question

C

Chris Dutton

Hi,

I'm using eRuby and mod_ruby to write some simple *.rhtml pages (I just
switched to a host with decent support for Ruby), but there's one thing
that's got me scratching my head.

How do I set cookies?

eRuby's handling all of the HTTP headers for, so by the time I get
control back, it's too late. If I recall correctly, there's a
"no-header" flag, but I don't really want to have to menually output the
normal headers on every page.

I'd appreciate any light you might be able to shed on this.

Thanks,
Chris
 
P

paul vudmaska

Chris Dutton said:
Hi,

I'm using eRuby and mod_ruby to write some simple *.rhtml pages (I just
switched to a host with decent support for Ruby), but there's one thing
that's got me scratching my head.

How do I set cookies?

eRuby's handling all of the HTTP headers for, so by the time I get
control back, it's too late. If I recall correctly, there's a
"no-header" flag, but I don't really want to have to menually output the
normal headers on every page.

I'd appreciate any light you might be able to shed on this.

Thanks,
Chris

Something like this is working on my host:
%> cookie.rhtml

<%
begin
require 'cgi'

COOKIE_NAME = 'mycookie'

cgi = CGI.new

if cgi.cookies[COOKIE_NAME][0]

puts 'cookie found : ' + cgi.cookies[COOKIE_NAME][0]

else

puts 'settting cookie'

cookie = CGI::Cookie.new ({'name'=>COOKIE_NAME,'value'=>'cookie
value','expires'=>Time.now + (2400*24*365)})

cgi.header({'cookie'=>[cookie]})

end

rescue Exception

puts $!
end

%>

So the headers might not be the problem.

:paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top