Module: CollectiveIdea::RemoteLocation

Defined in:
lib/acts_as_geocodable/remote_location.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#remote_locationObject

Get the remote location of the request IP using hostip.info



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/acts_as_geocodable/remote_location.rb', line 5

def remote_location
  if request.remote_ip == '127.0.0.1'
    # otherwise people would complain that it doesn't work
    Graticule::Location.new(:locality => 'localhost')
  else
    Graticule.service(:host_ip).new.locate(request.remote_ip)
  end
rescue Graticule::Error => e
  logger.warn "An error occurred while looking up the location of '#{request.remote_ip}': #{e.message}"
  nil
end