I am using active record sessions and everything works fine. I am integrating it with phpbb however so i need some extra fields populated in the session table. In application.rb i put a before_filter to update the session table I have a model for the sessions $ more app/models/session.rb class Session < ActiveRecord::Base set_primary_key "session_id" set_table_name "phpbb_sessions" end and a before_filter: session_hash = { "session_user_id" => @entry.user_id, "session_ip" => encode_ip, "session_time" => Time.now , "session_logged_in" => 1} @tmpsess = Session.find_by_session_id(session.session_id) @tmpsess.update_attributes(session_hash) if @tmpsess the logfile then shows : UPDATE phpbb_sessions SET "data" ''BAh7EjoOZGVmX3N0YXRlIgdOWToIbGF0Zho0MC42NTk5OTk5OTk5OTk5OTcArhQ6DGRlZl9sYXQwOglsb25nZhstNzMuOTgwMDAwMDAwMDAwMDA0AIUfOgh1'', "session_start" = 0, "session_user_id" = 3, "session_admin" = 0, "session_time" = 1148349972, "session_logged_in" = 1, "id" = 22, "session_page" = 0, "session_ip" = ''185afae3'', "updated_at" = ''2006-05-22 22:06:12'' WHERE session_id = ''a1f7912ebd968e7136e10d6d67021680'' However the extra fields dont get updated. running this manually in postgres works as expected. is there some sort of limitation on the session table that would cause this behavior ? thanks for any input adam -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060523/42744210/attachment.html
found the answer here http://wiki.rubyonrails.com/rails/pages/HowtoChangeSessionStore however it doesnt really explain why this guy was "pulling his hair out". But apparently the fix is to use the "model" method to access the session model correctly. session.model.session_user_id = 3 seems to do it. adam On 5/22/06, Adam Denenberg <straightflush@gmail.com> wrote:> > I am using active record sessions and everything works fine. I am > integrating it with phpbb however so i need some extra fields populated in > the session table. In application.rb i put a before_filter to update the > session table > > I have a model for the sessions > > $ more app/models/session.rb > class Session < ActiveRecord::Base > set_primary_key "session_id" > set_table_name "phpbb_sessions" > end > > and a before_filter: > session_hash = { "session_user_id" => @entry.user_id, "session_ip" => > encode_ip, "session_time" => Time.now , "session_logged_in" => 1} > @tmpsess = Session.find_by_session_id(session.session_id) > @tmpsess.update_attributes(session_hash) if @tmpsess > > the logfile then shows : > > UPDATE phpbb_sessions SET > "data" > ''BAh7EjoOZGVmX3N0YXRlIgdOWToIbGF0Zho0MC42NTk5OTk5OTk5OTk5OTcArhQ6DGRlZl9sYXQwOglsb25nZhstNzMuOTgwMDAwMDAwMDAwMDA0AIUfOgh1'', > "session_start" = 0, "session_user_id" = 3, "session_admin" = 0, > "session_time" = 1148349972, "session_logged_in" = 1, "id" = 22, > "session_page" = 0, "session_ip" = ''185afae3'', "updated_at" = ''2006-05-22 > 22:06:12'' WHERE session_id = ''a1f7912ebd968e7136e10d6d67021680'' > > > However the extra fields dont get updated. running this manually in > postgres works as expected. is there some sort of limitation on the session > table that would cause this behavior ? > > thanks for any input > adam >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060523/9d8364ed/attachment.html
Does anyone know how to create a default value for the insert of a new session record? I found out why the default value for session_user_id is 0 instead of 1. Rails is using an insert statement and setting all the other fields to 0 instead of leaving them alone. Here is the query i found. INSERT INTO phpbb_sessions ("updated_at", "session_start", "session_id", "session_time", "session_ip", "session_admin", "session_page", "session_logged_in", "data", "session_user_id") VALUES(''2006-05-23 08:48:04'', 0, ''2d946283ea3c1a16695978ad6e812960'', 0, ''0'', 0, 0, 0, ''BAh7BzoIdXJpIgYvIgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVyOjpGbGFz '', 0) Is there anyway to override session_user_id to make the insert a ''1'' instead of a 0 ? I set a "default" value in postgres but that doesnt seem to work. thanks adam On 5/22/06, Adam Denenberg <straightflush@gmail.com> wrote:> > found the answer here > http://wiki.rubyonrails.com/rails/pages/HowtoChangeSessionStore > > however it doesnt really explain why this guy was "pulling his hair out". > But apparently the fix is to use the "model" method to access the session > model correctly. > > session.model.session_user_id = 3 seems to do it. > > adam > > > On 5/22/06, Adam Denenberg <straightflush@gmail.com > wrote: > > > > I am using active record sessions and everything works fine. I am > > integrating it with phpbb however so i need some extra fields populated in > > the session table. In application.rb i put a before_filter to update > > the session table > > > > I have a model for the sessions > > > > $ more app/models/session.rb > > class Session < ActiveRecord::Base > > set_primary_key "session_id" > > set_table_name "phpbb_sessions" > > end > > > > and a before_filter: > > session_hash = { "session_user_id" => @entry.user_id, "session_ip" => > > encode_ip, "session_time" => Time.now , "session_logged_in" => 1} > > @tmpsess = Session.find_by_session_id(session.session_id) > > @tmpsess.update_attributes(session_hash) if @tmpsess > > > > the logfile then shows : > > > > UPDATE phpbb_sessions SET > > "data" > > ''BAh7EjoOZGVmX3N0YXRlIgdOWToIbGF0Zho0MC42NTk5OTk5OTk5OTk5OTcArhQ6DGRlZl9sYXQwOglsb25nZhstNzMuOTgwMDAwMDAwMDAwMDA0AIUfOgh1'', > > "session_start" = 0, "session_user_id" = 3, "session_admin" = 0, > > "session_time" = 1148349972, "session_logged_in" = 1, "id" = 22, > > "session_page" = 0, "session_ip" = ''185afae3'', "updated_at" = ''2006-05-22 > > 22:06:12'' WHERE session_id = ''a1f7912ebd968e7136e10d6d67021680'' > > > > > > However the extra fields dont get updated. running this manually in > > postgres works as expected. is there some sort of limitation on the session > > table that would cause this behavior ? > > > > thanks for any input > > adam > > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060523/f88bbabc/attachment-0001.html