3
votes

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

1
The object you are calling city on is the nil object. Find out why you are getting nil and not a valid request. - Fred
But in ubuntu server it works very well, the code example is :ciudad => request.location.city - rderoldan1
request.location is nil, or you wouldn't be getting that error. See what your debugger thinks. - Fred
Yes I'm agree with you, but the question is why in Ubuntu server request.location is working and in Redhat not - rderoldan1
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

1 Answers

9
votes

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>]