Question

I dont know exactly why but the gem is working properly except by the fact that it appears to not obbey the configuration file.

When I test its initialization with a 'puts' command it show in the console that the file is beeing readed.

The central problem is that i want to make my geocoder gem to use the method lookup to determine the user location with maxmind's or google's ip location services because freegeoip just give me wrong results.

Here is my /config/initializers/geocoder.rb file witch i created by myself:

# config/initializers/geocoder.rb

def self.options_and_defaults
  [
      # geocoding service timeout (secs)
      [:timeout, 3],

      # name of geocoding service (symbol)
      [:lookup, :google],

      # ISO-639 language code
      [:language, :en],

      # use HTTPS for lookup requests? (if supported)
      [:use_https, false],

      # HTTP proxy server (user:pass@host:port)
      [:http_proxy, nil],

      # HTTPS proxy server (user:pass@host:port)
      [:https_proxy, nil],

      # API key for geocoding service
      [:api_key, nil],

      # cache object (must respond to #[], #[]=, and #keys)
      [:cache, nil],

      # prefix (string) to use for all cache keys
      [:cache_prefix, "geocoder:"],

      # exceptions that should not be rescued by default
      # (if you want to implement custom error handling);
      # supports SocketError and TimeoutError
      [:always_raise, []]
  ]
end

I also used this code with my google api code and google for lookup, and with maxmind... both returns me that actually geocoder still uses freegeoip

I implemented a 'puts' entry on my controller with:

puts 'oioioi'
puts request.ip
puts Geocoder.search(request.ip).first
puts request.location  

so i could detect it on the console output.

I got:

oioioi
127.0.0.1
#<Geocoder::Result::Freegeoip:0x007fbe846eb258>
#<Geocoder::Result::Freegeoip:0x007fbe847232e8> 

I know that im using a local IP but i already tested on deplyoment and the fact is that the lookup is still using Freegeoip as lookup server.

Hope anybody could help me... Thanks in advance.

Was it helpful?

Solution

I wasn't using the right config. I needed to set :ip_lookup to get it working.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top