module Geokit::IpGeocodeLookup
Contains a class method geocode_ip_address which can be used to enable automatic geocoding for request IP addresses. The geocoded information is stored in a cookie and in the session to minimize web service calls. The point of the helper is to enable location-based websites to have a best-guess for new visitors.
Private Instance Methods
get_ip_address()
click to toggle source
Returns the real ip address, though this could be the localhost ip address. No special handling here anymore.
# File lib/geokit-rails/ip_geocode_lookup.rb, line 44 def get_ip_address request.remote_ip end
store_ip_location()
click to toggle source
Places the IP address' geocode location into the session if it can be found. Otherwise, looks for a geo location cookie and uses that value. The last resort is to call the web service to get the value.
# File lib/geokit-rails/ip_geocode_lookup.rb, line 29 def store_ip_location session[:geo_location] ||= retrieve_location_from_cookie_or_service cookies[:geo_location] = { :value => session[:geo_location].to_yaml, :expires => 30.days.from_now } if session[:geo_location] end