Hi, How can i access to request.remote_ip in a model? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
request.env["REMOTE_ADDR"] On 7/9/07, Jean-Sébastien <jeansebastien.ney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > How can i access to request.remote_ip in a model? > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
One way would be to set a Thread local variable in a before_filter. See: http://www.zorched.net/2007/05/29/making-session-data-available-to-models-in-ruby-on-rails/ Cheers, Rob On 7/9/07, Jean-Sébastien <jeansebastien.ney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > How can i access to request.remote_ip in a model? > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. On 7/9/07, Rob Bevan <robbevan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > One way would be to set a Thread local variable in a before_filter. > See: http://www.zorched.net/2007/05/29/making-session-data-available-to-models-in-ruby-on-rails/ > > Cheers, > Rob > > On 7/9/07, Jean-Sébastien <jeansebastien.ney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi, > > How can i access to request.remote_ip in a model? > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Jul 9, 2:31 pm, "Chris Hall" <christopher.k.h...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > > On 7/9/07, Rob Bevan <robbe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > One way would be to set a Thread local variable in a before_filter. > > See:http://www.zorched.net/2007/05/29/making-session-data-available-to-mo... > > > Cheers, > > Rob > > > On 7/9/07, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi, > > > How can i access to request.remote_ip in a model?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. On 7/9/07, Jean-Sébastien <jeansebastien.ney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 > > On Jul 9, 2:31 pm, "Chris Hall" <christopher.k.h...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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. > > > > On 7/9/07, Rob Bevan <robbe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > One way would be to set a Thread local variable in a before_filter. > > > See:http://www.zorched.net/2007/05/29/making-session-data-available-to-mo... > > > > > Cheers, > > > Rob > > > > > On 7/9/07, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Hi, > > > > How can i access to request.remote_ip in a model? > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
i want ip address for user model on a "before_create" method, and store ip address on each connection. On Jul 10, 1:26 am, "Chris Hall" <christopher.k.h...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > > On 7/9/07, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > 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 > > > On Jul 9, 2:31 pm, "Chris Hall" <christopher.k.h...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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. > > > > On 7/9/07, Rob Bevan <robbe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > One way would be to set a Thread local variable in a before_filter. > > > > See:http://www.zorched.net/2007/05/29/making-session-data-available-to-mo... > > > > > Cheers, > > > > Rob > > > > > On 7/9/07, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Hi, > > > > > How can i access to request.remote_ip in a model?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 the session (below is just an idea, not tested) ApplicationController < ActionController::Base before_filter :init_user private def init_user session[:user] ||= User.new(:ip => request.env["REMOTE_IP"]) end end then when you are ready, just save the user object from the session session[:user].save 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. Chris On 7/10/07, Jean-Sébastien <jeansebastien.ney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > i want ip address for user model on a "before_create" method, and > store ip address on each connection. > > On Jul 10, 1:26 am, "Chris Hall" <christopher.k.h...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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. > > > > On 7/9/07, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > 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 > > > > > On Jul 9, 2:31 pm, "Chris Hall" <christopher.k.h...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > 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. > > > > > > On 7/9/07, Rob Bevan <robbe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > One way would be to set a Thread local variable in a before_filter. > > > > > See:http://www.zorched.net/2007/05/29/making-session-data-available-to-mo... > > > > > > > Cheers, > > > > > Rob > > > > > > > On 7/9/07, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > Hi, > > > > > > How can i access to request.remote_ip in a model? > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---