3

In my sesions table I'm storing country and city name using the request method, now, in ubuntu server it works well but in redhat I am getting this error

NoMethodError (undefined method `city' for nil:NilClass)

I have tried this issue solution and I restarted my server but it doesn't work for me.

In both servers I am using Passenger + Apache

rderoldan1
  • 3,517
  • 26
  • 33
  • The object you are calling `city` on is the nil object. Find out why you are getting nil and not a valid request. – Fred Aug 17 '13 at 04:58
  • But in ubuntu server it works very well, the code example is :ciudad => request.location.city – rderoldan1 Aug 17 '13 at 04:59
  • request.location is nil, or you wouldn't be getting that error. See what your debugger thinks. – Fred Aug 17 '13 at 05:15
  • Yes I'm agree with you, but the question is why in Ubuntu server request.location is working and in Redhat not – rderoldan1 Aug 17 '13 at 18:29
  • Who knows? There could be a bug in the interpreter or library on your RH machine your program tickles; there could be a bug in the interpreter or library on the Ubuntu machine that hides a bug in your program; or something else. I can't diagnose it from the info at hand. You'll just have to see what the debugger reveals. – Fred Aug 17 '13 at 22:59
  • I found that the error was related with the timeout param – rderoldan1 Aug 20 '13 at 16:12
  • Possible solution here: http://stackoverflow.com/questions/26093393/geocoding-api-not-responding-fast-enough-for-ip-address I hope this help you! – Lucas Ocon Jan 05 '15 at 05:33

1 Answers1

9

I have found the issue, it was that the search IP was taking too much time, so I created an initializer and changed the default timeout

config/initializer/geocoder.rb

Geocoder.configure(
 :timeout => 20
)

How I found

I open the rails c and search my IP

$ location = Geocoder.search("myIpAddres")
Geocoding API not responding fast enough (use Geocoder.configure(:timeout => ...) to set limit).
=> []

Now it works

$ location = Geocoder.search("myIpAddres")
=> [#<Geocoder::Result::Freegeoip:0xa7130b8 @data={"ip"=>"myIpAddres", "country_code"=>"CO", "country_name"=>"Colombia", "region_code"=>"02", "region_name"=>"Antioquia", "city"=>"Medellín", "zipcode"=>"", "latitude"=>6.2518, "longitude"=>-75.5636, "metro_code"=>"", "areacode"=>""}, @cache_hit=nil>]
rderoldan1
  • 3,517
  • 26
  • 33