Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4.1.6 session ID

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]
like image 598
kashif Avatar asked Nov 05 '14 10:11

kashif


People also ask

What is Session ID Rails?

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.

Where sessions are stored in Rails?

Rails store it in server side. Session is saved in server side like key value pair (like json object)

How sessions are created in Rails?

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.


1 Answers

session.id

This is the correct way to do it.

like image 56
madcow Avatar answered Sep 17 '22 15:09

madcow