views:

28

answers:

1

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.

But the following method of setting cookies 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.

A: 

It turns out that you can't use an IP address with cookies, at least not with also specifying a port.

aharon