Finding the Session Id in Rails 3

Finding the session id in rails 3

Have you tried the following?

request.session_options[:id]

Finding User ID from Sessions

As indicated by @Bohdan, you may want to shorten your code a bit like this:

Activity.log( session[:user_id] )

In your case, you don't have to rely on ActiveRecord mechanisms.

Getting Session ID value

How are you creating the sessions? What's the output of session.inspect? If they are in a model, you can use session.id. If they are stored in an array or hash, you may have to first identify the individual like session[0][:session_id].

The correct answer turned out to be session.session_id.

Thanks!

How can I find a devise user by it's session id?

At least on my system (rails 3.2, devise 2.0.4), you can do it like this:

session is:

{"session_id"=>"be02f27d504672bab3408a0ccf5c1db5", "_csrf_token"=>"DKaCNX3/DMloaCHbVSNq33NJjYIg51X0z/p2T1VRzfY=", "warden.user.user.key"=>["User", [3], "$2a$10$5HFWNuz5p6fT3Z4ZvJfQq."]}

session["warden.user.user.key"][1][0], then is 3.

So, I'd find it as:

User.find(session["warden.user.user.key"][1][0])

Sessions and user_id in rails

In your create method it should be

session[:user_id] = user.id

You are setting up a key :user_id in the session hash and storing the authenticated user's id user.id in it for later use

Key name can be anything



Related Topics



Leave a reply



Submit