开发者

setting cookies

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜