Take the 2-minute tour ×  I'd like to do the following:  define
a before_filter in application.rb that extracts the user's IP
address and stores it anywhere, preferably in the session.
define two before filters in all my models as before_create and
before_update that add the current user's IP to the object to be
stored.  Problem: I cannot access session[] neither env[] in a
model. Can anyone help with a standard solution that I don't
know yet?  Regards Jason  share|improve this question add
comment  5 Answers  Try this. In your user model add a class
attribute accessor  cattr_accessor :current_ip  In your
application controller add:  before_filter :set_current_ip  def
set_current_ip     User.current_ip = request.env['REMOTE_ADDR']
Then in your model you should be able to just call
User.current_ip  We do something similar to get the current_user
object passed through.  share|improve this answer One note to
this is that the REMOTE_ADDR is sometimes a list of IP addresses
depending on your setup. –  Lee Irving