Simple eRuby question

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

Chris Dutton rubyguru@hotmail.com wrote in message news:WCxpc.465258$Pk3.248561@pd7tw1no

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 + (240024365)})

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

end

rescue Exception

puts $!

end

%>

So the headers might not be the problem.

:Paul