Sandeep Gudibanda
2008-Feb-13 20:47 UTC
Accessing entire current SESSION row - Not just DATA column
Hi, I am in need to perform left join between my friends table and In built sessions table: LEFT JOIN sessions ON sessions.user_id=friendships.friend_id To do this, I have altered sessions table to have user_id apart from what i wud store in session data. session[:user_id] points to user_id in Data Hash. session.user_id throws me an error.(undefined method user_id) How do i set this user_id for the session row when someone logs in? How can I access session table? How will I know the current session id? Regards, Sandeep G -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeremy Kemper
2008-Feb-13 20:56 UTC
Re: Accessing entire current SESSION row - Not just DATA column
On 2/13/08, Sandeep Gudibanda <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I am in need to perform left join between my friends table and In built > sessions table: > > LEFT JOIN sessions ON sessions.user_id=friendships.friend_id > > To do this, I have altered sessions table to have user_id apart from > what i wud store in session data. > > session[:user_id] points to user_id in Data Hash. > session.user_id throws me an error.(undefined method user_id) > > How do i set this user_id for the session row when someone logs in? How > can I access session table? How will I know the current session id?You can use session.model to get at the underlying session record. You can even reopen CGI::Session::ActiveRecordStore::Session to add associations if you like. jeremy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sandeep Gudibanda
2008-Feb-14 05:14 UTC
Re: Accessing entire current SESSION row - Not just DATA col
Thanks Jeremy! session.model worked fine for current sessions. I am able to set user_ids for sessions henceforth. Another issue is, Now that I have added user_id to sessions, I need to set that for existing rows as well.I tried to do that with: stored_sessions = CGI::Session::ActiveRecordStore::Session.find(:all) stored_sessions.each do |stored_session| id = Marshal.load( Base64.decode64( stored_session[''data''] ) ) stored_session[''user_id''] = id[:user_id] stored_session.save end But save part does''nt work. I tried something fancy like this: id[''model''].update_attribute(:user_id, id[:user_id]) Only to get syntax error... What I am missing here? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---