开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜