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
Get Last Day of the Month in Ruby
How to Include Video in Jekyll Markdown Blog
Rails 4 How to Ignore Pending Migrations
How to Filter Parameters in Rails
Why Does Accessing a Ssl Site with Mechanize on Windows Fail, But on MAC Work
Options for Distribution of an Offline Ruby on Rails Application
Ruby Gem Not Found Although It Is Installed
How to Test If a Div Has a Certain CSS Style in Rspec/Capybara
Rails: Opposite of Hash#To_Param
Skip Over Iteration in Enumerable#Collect
Finding the Session Id in Rails 3
In Ruby What Does "=>" Mean and How Does It Work
Ruby/Rails - .Each Iterator Is Printing Entire Array at the End of the Loop
Coding Style Checker or Code Formatter for Ruby/Rails