Accessing session data using session_id


This is the very rare case but some times we need to access the data stored in session through session_id(specially when the request is not coming from browser). Here is a way I found and like to share:

@user=CGI::Session::ActiveRecordStore::Session.find_by_session_id(@session_id).data[:user]

Sponsors

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.


Other Posts
Excellent! what else I say about Barcamp Delhi 2
BarCampDelhi-2: see you there…
If my code or post helps you then please recommend me at workingwithrails.com by clicking on button below:
Recommend Me

Reader Comments

This was the line a realy needed. Thanks so much.

Great stuff. Many thanks!

Thanks a lot mate

zVOoYG hi nice site thx http://peace.com

thanks for sharing dude!

thanks for the great info

great rails

Thanks for sharing, i would not have enjoyed figuring this out myself.

Enjoyed the read, will bookmark.

It’s good to receive the data from a specific session id, but in my case, the current session id keeps changing because there is no cookie enabled in my browser. The session database (I set the sessions to be stored in database) is full of useless sessions since the new request will receive a new session id. Is there a way to reuse the current session id in a new request without cookie? Thnx.

Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.