Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

26 lines (23 sloc) 0.622 kb
module Geocoder
module Request
def location
@location ||= begin
detected_ip = env['HTTP_X_REAL_IP'] || (
env['HTTP_X_FORWARDED_FOR'] &&
env['HTTP_X_FORWARDED_FOR'].split(",").first.strip
)
detected_ip = IpAddress.new(detected_ip.to_s)
if detected_ip.valid? and !detected_ip.loopback?
real_ip = detected_ip.to_s
else
real_ip = self.ip
end
Geocoder.search(real_ip).first
end
@location
end
end
end
if defined?(Rack) and defined?(Rack::Request)
Rack::Request.send :include, Geocoder::Request
end
Jump to Line
Something went wrong with that request. Please try again.