Вопрос

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

Это было полезно?

Решение

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>]
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top