How can i access to request.remote_ip in a model?
One way would be to set a Thread local variable in a before_filter.
duh, i misread the OP, didn't see the "in a model" part.
i would recommend you pass it as a parameter to a method.
so that's able to call it from parent object, something like it (i'm
not sure about the parent class) : CGI::Request.remote_ip
i didn't really understand your reply.
to be clear, what you want to do is pass the remote ip in as a
parameter to one of the models methods. I'm not sure what it is you
are trying to accomplish, so without further info, there's not much
more assistance i can provide.
i want ip address for user model on a "before_create" method, and
store ip address on each connection.
what i might do in this case is instantiate a new user object and
initialize it with the ip you want to store. keep this instance in
(below is just an idea, not tested)
ApplicationController < ActionController::Base
session[:user] ||= User.new(:ip => request.env["REMOTE_IP"])
then when you are ready, just save the user object from the session
and it will already have the ip address. no need for anything fancy
again, not sure if that would work, but that is route i would take for
something like this.
hope that helps.