Trying to get to REMOTE_ADDR

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.

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