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.