Forum: Ruby on Rails request.env not accessible in controller

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
0cfa43ade56eed9cabe9fa21d85dd805?d=identicon&s=25 gabordemeter (Guest)
on 2007-06-15 21:33
(Received via mailing list)

I have the simplest rails app:

my only controller says:

class MaxmindController < ApplicationController
  @ip = request

my index.rhtml in the views/maxmind folder says:

<%= debug @ip %>

the result of trying to view this in firefox is:

NameError in MaxmindController#index

undefined local variable or method `request' for

if I remove the one line from my controller and change my view code

<%= debug request %>

then i get my request object nicely displayed.

Why is request available only in the view and not in the controller?
I'm running this locally under locomotive.


6ef8cb7cd7cd58077f0b57e4fa49a969?d=identicon&s=25 Brian Hogan (Guest)
on 2007-06-15 21:41
(Received via mailing list)
Because you're out of scope. @ip = request is in the class scope, and
request is not available there.

Try using a before_filter.

class MaxmindController < ApplicationController
  before_filter :get_ip

   def get_ip
     @ip = request.remote_ip

This topic is locked and can not be replied to.