我尝试实现购物车,我写了这段代码:
if cookies[:shopping_cart]
Cart.find(cookies[:shopping_cart][:value])
else
cookies[:test] = 'tt'
cart = Cart.create
cookies[:shopping_cart] = {
:value => cart.id,
:expires => 1.week.from_now.utc,
:path => '/',
:domain => 'localhost:3000'
}
end
但每次我有cookies [:shopping_cart]为零,每次我的“代码”尝试创建新的cookies [:shopping_cart]。
cookies [:test]每次也等于零。
建议?
答案 0 :(得分:0)
我删除
:path => '/',
:domain => 'localhost:3000'
现在有效!!
答案 1 :(得分:0)
从域名中删除端口号,因为cookie不会将端口视为it stores the same cookie for the any port of the same server(RFC6265)
:domain => 'localhost'