I''ve just upgraded to Rails 2.3.2. I am using active_record_store as my session approach and session.model is deprecated. I was using that to update a couple extra session db columns. Does anyone knows what is the best approach for that now, since ActiveRecord::SessionStore does not help that much? thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Mar 26, 12:45 pm, Danilo Castilho <dncasti...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve just upgraded to Rails 2.3.2. I am using active_record_store as > my session approach and session.model is deprecated. I was using that > to update a couple extra session db columns. Does anyone knows what is > the best approach for that now, since ActiveRecord::SessionStore does > not help that much?I had the exact same problem, and I couldn''t find any help anywhere. So I played with it until I got it to work. This is what I did to put the user id in the sessions table upon login: In session.rb: class Session < ActiveRecord::Base def self.update_user_id(id, sess_id) connection.update("UPDATE sessions SET user_id = ''#{id}'' WHERE session_id = ''#{sess_id}''") end end In login action in the controller: if session[:userid] = User.authenticate(params[:user][:username], params[:user][:password]) Session.update_user_id(session[:userid], request.session.session_id) [...] IOW, this: session.model.user_id = session[:userid] becomes this: Session.update_user_id(session[:userid], request.session.session_id) Apparently one has to call "session[:userid]" or in order to "activate" the session since it is now lazy (ie it won''t load unless you access it). Otherwise, the "request.session.session_id" part won''t work. Hope this helps! --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Your suggestion helped a lot! I''ve followed a slightly different approach, but using your idea. What I did was add the following private method in my login controller: def session_user_id(id) ActiveRecord::Base.connection.update("UPDATE sessions SET user_id #{id} WHERE session_id = ''#{request.session.session_id}''") end And then I just do this in the login action: session[:user] = user.id session_user_id(session[:user]) I think that there is an advantage in this approach. No need to deal with any custom session classes and the method is only available where it should be. cheers! On Wed, Apr 1, 2009 at 9:17 PM, Scottie35 <scottie-PiS7C4ro6f9WS87MicF4CWGXanvQGlWp@public.gmane.org> wrote:> > On Mar 26, 12:45 pm, Danilo Castilho <dncasti...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I''ve just upgraded to Rails 2.3.2. I am using active_record_store as > > my session approach and session.model is deprecated. I was using that > > to update a couple extra session db columns. Does anyone knows what is > > the best approach for that now, since ActiveRecord::SessionStore does > > not help that much? > > I had the exact same problem, and I couldn''t find any help anywhere. > So I played with it until I got it to work. This is what I did to put > the user id in the sessions table upon login: > > In session.rb: > > class Session < ActiveRecord::Base > def self.update_user_id(id, sess_id) > connection.update("UPDATE sessions SET user_id = ''#{id}'' > WHERE > session_id = ''#{sess_id}''") > end > end > > In login action in the controller: > > if session[:userid] = User.authenticate(params[:user][:username], > params[:user][:password]) > Session.update_user_id(session[:userid], request.session.session_id) > [...] > > IOW, this: > > session.model.user_id = session[:userid] > > becomes this: > > Session.update_user_id(session[:userid], request.session.session_id) > > Apparently one has to call "session[:userid]" or in order to > "activate" the session since it is now lazy (ie it won''t load unless > you access it). Otherwise, the "request.session.session_id" part won''t > work. > > Hope this helps! > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---