Possible to add request IP column in session table?

Is there a way to add a column in the session table (using MySQL) to
record the requester’s IP address?

Or possibly extend the session code to write to another table or log
file that I could use to correlate session and requester IP address.

I need this short term for a debugging task.

– gw

The easiest way may be to add a “before_filter”,

class ApplicationController < ActionController::Base

before_filter :save_request_ip

def save_request_ip
session[:request_ip] = request.remote_ip
protected :save_request_ip



rest of your ApplicationController code




Then read back the value from session[:request_ip] as needed.

The requester’s IP may change from request to request, if they have
IP’s assigned dynamically, for example. Not quite clear how this would
be a “short term debugging requirement”. Also may require browser has
“cookies enabled”, depending on what you’re up to.


On Apr 11, 4:25 pm, Greg W. [email protected]