how to get the persistent cookie value and session cookie value in rails application

大憨熊 提交于 2021-02-11 01:14:08

问题


Im developing ruby on rails application. I want to get the persistent cookie value and session cookie value in the application. Can any please guide me on this

I have read that request.session_options[:id] will fetch the session_id, is that the one that is usually stored in session cookie? Please guide me if my way of understanding is wrong.Thanks in advance


回答1:


In Rails, it is simple as calling the session or cookies hash.

# Set a simple session cookie
cookies[:user_name] = "david" 
# Read a cookie 
cookies[:user_name]  # => "david"
# Delete a key
cookies.delete :user_name

The same goes for session. So, the information that you are looking for is probably inside one of these two.

Take a look at the examples at http://www.tutorialspoint.com/ruby-on-rails/rails-session-cookies.htm



来源:https://stackoverflow.com/questions/25505689/how-to-get-the-persistent-cookie-value-and-session-cookie-value-in-rails-applica

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!