How to get session id from a request object. Below code can be used in Rails 3 to get the session ID. But this doesn't seem to be working any more in Rails 4.1.6 and Ruby 2.1.3
request.session_options[:id]
A session id consists of the hash value of a random string. The random string is the current time, a random number between 0 and 1, the process id number of the Ruby interpreter (also basically a random number) and a constant string. Currently it is not feasible to brute-force Rails' session ids.
Rails store it in server side. Session is saved in server side like key value pair (like json object)
The rails way of creating a session is just using 'session[:user_id] = user.id'. This will create a session with the user_id. The current_user method will return the current user if there is one or if there is a session present. That means if a user is logged in, the current user will be the that user.
session.id
This is the correct way to do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With