如何在使用通配符域设置的rails中删除Cookie?
cookies[:foo] = {:value => 'bar',:domain => '.acme.com'}
在docs之后,你做:
cookies.delete :foo
日志说
Cookie set: foo=; path=/; expires=Thu,01 Jan 1970 00:00:00 GMT
请注意,域丢失(似乎使用默认值)
一切的参数).尊重RFC,当然是cookie的
还有,浏览器 – > ctrl / cmd-L – >
javascript:alert(document.cookie);
瞧!
解决方法
通过删除的域:以下是该方法的来源:
# Removes the cookie on the client machine by setting the value to an empty string # and setting its expiration date into the past. Like []=,you can pass in an options # hash to delete cookies with extra data such as a +path+. def delete(name,options = {}) options.stringify_keys! set_cookie(options.merge("name" => name.to_s,"value" => "","expires" => Time.at(0))) end
正如你所看到的,它只是设置一个空的cookie与你给的名字,设置为在1969年到期,没有内容.但它会合并您提供的任何其他选项,所以你可以做:
cookies.delete :foo,:domain => '.acme.com'
你设置好了