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)
[...]
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.
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
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.