Finding the session id in rails 3

Ruby on-RailsRubySession

Ruby on-Rails Problem Overview


How can I get the current session id in rails 3?

I've tried the following with no luck:

session[:session_id]
session['session_id']
session[:id]
session['id']
session.id
session.session_id

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

Have you tried the following?

request.session_options[:id]

Solution 2 - Ruby on-Rails

It also returns the session ID:

session[:session_id]

Solution 3 - Ruby on-Rails

If you need to see data written in Session store for given session id from Rails console you can:

a = Rails.application.config.session_store.new(app, Rails.application.config.session_options)
a.class # => ActionDispatch::Session::RedisStore
a.get_session(ENV, '07319b2485be9ac4850664cd47cede38')
                                                        

# or a.find_session(ENV, '07319b2485be9ac4850664cd47cede38')

app andENV are set when you start rails console, don't need to set those

you can get the session_id via some a browser plugin dealing with cookies or (cookie inspector, cookies manager, ...)

Solution 4 - Ruby on-Rails

Rails 4.0 onwards should be:

session.id

Solution 5 - Ruby on-Rails

I can't test it right now but as far as I know the session id variable changed from 'id' to 'session_id' on Rails 3, have you tried that one? Hope it works for you.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAustinView Question on Stackoverflow
Solution 1 - Ruby on-RailssplicerView Answer on Stackoverflow
Solution 2 - Ruby on-RailswhatbirdView Answer on Stackoverflow
Solution 3 - Ruby on-Railsequivalent8View Answer on Stackoverflow
Solution 4 - Ruby on-RailsestaniView Answer on Stackoverflow
Solution 5 - Ruby on-RailsRinoFMView Answer on Stackoverflow