2

I try to realize shopping cart, and i wrote this code:

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

But every time i have cookies[:shopping_cart] nil, and every time my "code" try to create new cookies[:shopping_cart].

cookies[:test] also equal nil every time.

that suggest?

prosto.vint
  • 1,403
  • 2
  • 17
  • 30

2 Answers2

0

Removing the port number from domain name, would work as the cookie won't consider the port as it stores the same cookie for the any port of the same server(RFC6265)

:domain => 'localhost'
Community
  • 1
  • 1
Charles
  • 1,008
  • 10
  • 21
0

i remove

:path => '/',
:domain => 'localhost:3000'

and it worked now!!

prosto.vint
  • 1,403
  • 2
  • 17
  • 30