Forum: Ruby on Rails additional fields in session DB table

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Adam D. (Guest)
on 2006-05-23 06:14
(Received via mailing list)
I am using active record sessions and everything works fine.  I am
integrating it with phpbb however so i need some extra fields populated
the session table.  In application.rb i put a before_filter to update
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"

and a before_filter:
session_hash = { "session_user_id" => @entry.user_id, "session_ip" =>
encode_ip, "session_time" => , "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" =
"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" =
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
table that would cause this behavior ?

thanks for any input
Adam D. (Guest)
on 2006-05-23 06:20
(Received via mailing list)
found the answer here

however it doesnt really explain why this guy was "pulling his hair
But apparently the fix is to use the "model" method to access the
model correctly.

session.model.session_user_id = 3 seems to do it.

Adam D. (Guest)
on 2006-05-23 16:56
(Received via mailing list)
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
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
to work.

This topic is locked and can not be replied to.