Module: GetGeolocationByUserIP

Included in:
ApplicationController
Defined in:
lib/extend.rb

Instance Method Summary collapse

Instance Method Details

#get_locationObject



3
4
5
6
7
8
9
10
11
# File 'lib/extend.rb', line 3

def get_location
  require 'open-uri'
  require 'json'
  ip = (RAILS_ENV == 'development') ? '169.232.0.0' : request.remote_ip
  if ip
    url = "http://freegeoip.net/json/#{ip}"
    @location = JSON.parse open(url).read
  end
end