0

I want to grab the visitors IP address and use it in my controller so that I can use geocoder to find nearby objects.

So I have a Location model, and I want to run a query like this:

def index
  @json = Location.near('visitor location here', 20).to_gmaps4rails
end

So I can show them a map pre-populated with the closest locations.

How do I access their IP address and use it in the controller? Can it be done? Should I be trying to accomplish this in the model using a scope?

Aaron Mills
  • 172
  • 1
  • 14

1 Answers1

5

From your controller:

request.remote_ip
Tolik Kukul
  • 1,996
  • 16
  • 26
  • Thanks! If anyone else gets stuck here, this is what I changed from the above example: def index @json = Location.near(request.remote_ip,20).to_gmaps4rails end – Aaron Mills Dec 19 '12 at 21:46