setting cookies

Posted by aharon on Stack Overflow See other posts from Stack Overflow or by aharon
Published on 2010-06-03T17:12:21Z Indexed on 2010/06/03 17:14 UTC
Read the original article Hit count: 269

Filed under:
|
|
|
|

Okay, so I'm trying to set cookies using Ruby. I'm in a Rack environment. response[name]=value will add an HTTP header into the HTTP headers hash rack has. I know that it works.

The following method doesn't work:

  def set_cookie(opts={})
    args = {
      :name     => nil,
      :value    => nil,
      :expires  => Time.now+314,
      :path     => '/',
      :domain    => Cambium.uri #contains the IP address of the dev server this is running on
    }.merge(opts)
    raise ArgumentError, ":name and :value are mandatory" if args[:name].nil? or args[:value].nil?
    response['Set-Cookie']="#{args[:name]}=#{args[:value]}; expires=#{args[:expires].clone.gmtime.strftime("%a, %d-%b-%Y %H:%M:%S GMT")}; path=#{args[:path]}; domain=#{args[:domain]}"
 end

Why not? And how can I solve it? Thanks.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about web-development