# Requesting a remote ip in plugin

**URL:** <https://www.ruby-forum.com/t/requesting-a-remote-ip-in-plugin/174132>\
**Category:** Rails\
**Created:** [August 21, 2009, 6:08am UTC](https://www.ruby-forum.com/t/requesting-a-remote-ip-in-plugin/174132 "2009-08-21T06:08:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9dc877/32.png) [@mahesh](https://www.ruby-forum.com/u/mahesh)\
**Post date:** [August 21, 2009, 6:08am UTC](https://www.ruby-forum.com/t/requesting-a-remote-ip-in-plugin/174132/1 "2009-08-21T06:08:20Z")

</div>

Im creating plugin for limiting the ip, i have included the plugin  
name in my controller

Controller:  
class AdminController \< ApplicationController

acts\_as\_ratelimit

def login  
session[:user\_id] = nil  
if request.post?  
user = User.authenticate(params[:name], params[:password])  
if user  
session[:user\_id] = user.id  
redirect\_to(:controller=\>“products”, :action =\> “new” )  
else  
flash.now[:notice] = “Invalid user/password combination”  
end  
end  
end

my plugin was initialize properly but im facing the problem in getting  
the remote ip in my plugin code .

i have included the line request.remote\_ip for getting the ip address,  
im facing the error us undefined method or variable as request

Is that any way to get the ip correctly.

---

<div class="post-metadata">

**Author:** ![mahesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9dc877/32.png) [@mahesh](https://www.ruby-forum.com/u/mahesh)\
**Post date:** [August 21, 2009, 4:46pm UTC](https://www.ruby-forum.com/t/requesting-a-remote-ip-in-plugin/174132/2 "2009-08-21T16:46:47Z")

</div>

@remote\_ip = request.remote\_ip

if apache is behind a mongrel remote\_ip might not work and you would  
have to do something similar:

@remote\_ip = request.env[“HTTP\_X\_FORWARDED\_FOR”]

def login  
@remote\_ip = request.remote\_ip  
…  
Your code  
…  
logger.error(“test: IP: #{@remote\_ip}” )  
end

Check your logs.

---

<div class="post-metadata">

**Author:** ![mahesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9dc877/32.png) [@mahesh](https://www.ruby-forum.com/u/mahesh)\
**Post date:** [August 23, 2009, 6:11am UTC](https://www.ruby-forum.com/t/requesting-a-remote-ip-in-plugin/174132/3 "2009-08-23T06:11:55Z")

</div>

thank you i got the answer

On Fri, Aug 21, 2009 at 8:16 PM, Alpha B. \<
