如何在Rails应用程序中获取持久性cookie值和会话cookie值

问题描述:

我正在开发Rails应用程序中的红宝石.我想在应用程序中获取持久性cookie值和会话cookie值.有什么可以指导我的吗

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

我已经阅读到request.session_options [:id]将获取session_id,这是通常存储在会话cookie中的那个吗?如果我的理解方式有误,请指导我.谢谢!

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

在Rails中,调用会话或cookie哈希很简单.

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.

http://www上查看示例.tutorialspoint.com/ruby​​-on-rails/rails-session-cookies.htm