# Trying to get to REMOTE\_ADDR

**URL:** <https://www.ruby-forum.com/t/trying-to-get-to-remote-addr/68257>\
**Category:** Rails\
**Created:** [September 11, 2006, 7:55am UTC](https://www.ruby-forum.com/t/trying-to-get-to-remote-addr/68257 "2006-09-11T07:55:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xtrmtrk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/7c8e57/32.png) [@xtrmtrk](https://www.ruby-forum.com/u/xtrmtrk)\
**Post date:** [September 11, 2006, 7:55am UTC](https://www.ruby-forum.com/t/trying-to-get-to-remote-addr/68257/1 "2006-09-11T07:55:22Z")

</div>

How does one go about finding the remote address of an HTTP request in  
Rails? I’ve got a fairly vanilla Rails application with the following  
code:

class GuestController \< ApplicationController

```
@remote_ip = request.env["REMOTE_ADDR"]

```

…  
end

The GuestController was created using the “generate controller” command  
and hasn’t been significantly modified.

When I try to run this (display a page), I get the error:

undefined local variable or method `request’ for GuestController:Class

I assume that this is a scoping issues. According to the docs it looks  
like request.env is implemented in ApplicationController’s parent  
ActionController. Why doesn’t this method call go up the inheritance  
chain? Seems like I’m missing something basic here.

Thanks.

---

<div class="post-metadata">

**Author:** ![xtrmtrk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/7c8e57/32.png) [@xtrmtrk](https://www.ruby-forum.com/u/xtrmtrk)\
**Post date:** [September 11, 2006, 11:22am UTC](https://www.ruby-forum.com/t/trying-to-get-to-remote-addr/68257/2 "2006-09-11T11:22:42Z")

</div>

request is accessible only from the instances of the controller class.

What you are trying to define here is a variable accessible for every  
single GuestController created, but defined only once when the server  
starts. Nonsense!

Use directly request.remote\_ip when you need in the actions!

Nauhaie
