Rails how to create cookies and call data later?
How do I create cookies in Rails?
Example a user visit:
http://mywebsite.com/ref/stackowerflow
Then I wa开发者_JS百科nt to safe stackowerflow
And call it later example
<%= ref %>
Output: stackowerflow
Creating cookie (preferably in controller):
cookies[:referer] = "stackoverflow"
Creating cookie that expires in an hour:
cookies[:referer] = { :value => "stackoverflow", :expires => Time.now + 1.hour}
Reading cookie:
ref = cookies[:referer] # "stackoverflow"
Deleting cookie:
cookies.delete :referer
精彩评论