Simple eRuby question

Discussion in 'Ruby' started by Chris Dutton, May 16, 2004.

  1. Chris Dutton

    Chris Dutton Guest

    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, May 16, 2004
    #1
    1. Advertising

  2. Chris Dutton <> 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 + (2400*24*365)})

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

    end

    rescue Exception

    puts $!
    end

    %>

    So the headers might not be the problem.

    :paul
     
    paul vudmaska, May 18, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg Brondo

    eruby setup question

    Greg Brondo, Apr 7, 2004, in forum: Ruby
    Replies:
    3
    Views:
    85
    Gennady
    Apr 7, 2004
  2. Greg Brondo

    erb question (was eruby question)

    Greg Brondo, Apr 7, 2004, in forum: Ruby
    Replies:
    0
    Views:
    89
    Greg Brondo
    Apr 7, 2004
  3. Dude
    Replies:
    2
    Views:
    116
    John Joyce
    Mar 22, 2007
  4. Chad Perrin

    simple eruby -- including files

    Chad Perrin, Mar 29, 2007, in forum: Ruby
    Replies:
    5
    Views:
    139
    John Joyce
    Mar 30, 2007
  5. Xeno Campanoli
    Replies:
    2
    Views:
    217
    Xeno Campanoli
    Sep 13, 2007
Loading...

Share This Page