I need to use a cookie for my Sinatra application. If I use the simpliest method is works:
response.set_cookie('my_cookie', 'value_of_cookie')
but I need some options such as domain and expire date so I try this:
response.set_cookie("my_cookie", {:value => 'value_of_cookie', :domain => myDomain, :path => myPath, :expires => Date.new})
d开发者_StackOverflowoes not work. No cookie is made. I need this so much....
Please help... thanks!
The documentation on http://sinatra-book.gittr.com/#cookies says to use the set_cookie helper, but in newer versions of Sinatra (at least from 1.2.0+ and possibly earlier), you should use response.set_cookie to set cookies.
response.set_cookie("my_cookie", :value => "value_of_cookie",
:domain => myDomain,
:path => myPath,
:expires => Date.new(2020,1,1))
cookie = request.cookies["my_cookie"]
SUMMARY
don't set localhost
as a domain for your cookies because you need to set it to "" or FALSE
精彩评论