In my Rails app with Devise, I'm making some home-made analytics that works, in part, the following way. If a user visits another user's profile, the show action of the user's profile checks whether the visitor is a registered user and, if so, it saves the user_id of the visitor to the database.
In my Rails 3 app, I could get the user_id of the visitor to the profile from the session like this
session['warden.user.user.key'][1]
That would, for example, give me the number '16' for user with id 16.
However, this didn't work when I remade my app with Rails 4. The first element of the array was no longer a number representing the user id. In my current Rails 4 app, i do
session['warden.user.user.key'][0]
However, I'm concerned that the elements of the array don't always come out in the same order. Therefore, this code session['warden.user.user.key'][0] might not work sometimes.
When I look at the session, however, I also notice that there is in several places a hash structure with a user_id like this
"user_id"=>16
but I can't figure out how to access it
Can anyone recommend what the most reliable way to get the user_id from the session is?