目前在 Rails 3.2.8 应用程序中遇到了这个问题,我的控制器中有这个调用:
cookies.delete :cookie_name
但是确实没有由 rails except 发出特殊的cookie头app_session
,所以cookie没有被删除,只是保持不变,添加域也没有效果:
cookies.delete :cookie_name, domain: 'localhost'
更新:完整的代码片段:
class BuyController < ApplicationController
COOKIE_KEY = :test
def index
@state = {}
if cookies.has_key?(COOKIE_KEY)
@state = Rack::Utils.parse_nested_query(cookies[COOKIE_KEY])
# this has no effect!
#cookies.delete COOKIE_KEY
# currently use this as workaround
cookies[COOKIE_KEY] = {value:''}
end
@configs = Option.all
end
end