How does a session work in Rails

I will learn about the session in rails. Most links say that the next way to create a session.

Example:

session[:id]=user.id

Session is a global hash. I doubt if the session is a global hash, then if multiple users try to log in, then does the session variable get overwritten or not? Because there will be only one global hash. So, if millions of users get a login, then how does the same "session [: id]" run all user sessions. Is it possible to store more than one value in one variable. As well as how to delete a session for a specific user. So how is a session handled on rails?

+4
source share
3 answers

sessionis not a global hash. This is a method that returns a new hash in the context of each request. How this hash is created depends on the main session store.

Let's look at 2 typical session repositories.

Encrypted cookie

This is the default session store for Rails applications. Rails serializes, then encrypts all session hashes into cookies and stores these cookies on clients (e.g., browsers). Each time a request hits the Rails application, Rails decrypts and then deserializes this session cookie into a hash. This hash is the method returned by the method session.

Redis Session Store

This session store does not ship with Rails. This is a separate stone.

Rails , ( ) ID- Redis. Rails cookie cookie . , Rails, Rails cookie, , Redis, . - , session.

+5

. ... Rails , . , .

, 32- , . cookie . round: .

http://guides.rubyonrails.org/security.html

, . "" , /.

+1

7stud, . HTTP "", , - , . . Rails (32 ), , cookie, , . , . , , , (, ..).

0
source

Source: https://habr.com/ru/post/1655234/


All Articles