Take the 2-minute tour ×

When I load my action CarsController#show in browser, I get this error message:

Timeout::Error in CarsController#show

execution expired

And the error pointing out on this line:

country = GeoIp.geolocation(ip, :precision => :country)

The whole action:

def show
    @car = Item.find_by_car_key(params[:car_key])

    ip = request.remote_ip
    geo_key = 'my geo key'
    GeoIp.api_key = geo_key
    puts country.inspect

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @item }

How can I avoid this error message and use it always when this action will be loaded?

Thank you

share|improve this question
What does GeoIp.geolocation do? Perhaps it's running a long process that's causing your request to time out? –  Chris Peters Sep 9 '13 at 17:14
GeoIp.geolocation(ip, :precision => :country) just find out the current location of the user who browse the website. "Perhaps it's running a long process that's causing your request to time out?" -> No, because I see the error like 1 second after entering the URL. The gem is called geo_ip. –  user984621 Sep 9 '13 at 17:23
Ruby debugger can help solve this type of problem. Put a debug statement in and check line by line to see what's failing and why. github.com/cldwalker/debugger –  mr.ruh.roh Sep 9 '13 at 18:14
If you made a question, please take time to give us feedback, you have a couple of asks, please review it –  rderoldan1 Sep 19 '13 at 3:26
add comment

2 Answers

I would recommend using the geocoder gem in combination with maxmind or freegeoip works well in my production app (freegeoip sometimes detects the wrong country, but its free)

share|improve this answer
add comment

Assuming you are using the GeoIP gem found here

The error is related with the time out, maybe geoip gem is taking to much time to fetch the ip info, so after your Api Key set GeoIp timeout

According to the gem readme,

It is possible to set a timeout for all requests. By default it is one second, but you can easily set a different value. Just like you would set the api_key you can set the timeout:


 GeoIp.timeout = 5 # In order to set it to five seconds


I will recommend you another gem, because geoip is nor uptodate, take a look at Geocoder https://github.com/alexreisner/geocoder, it can take the ip address from the request automatically like

share|improve this answer
maybe provide some doc of what the default timeout is.. if it's the same time that the OP is experiencing, this could be very valuable –  sircapsalot Sep 9 '13 at 17:34
It depends on which gem are you using, can you tell me? because in github.com/jeroenj/geo_ip#timeout the default is 1 second –  rderoldan1 Sep 9 '13 at 17:41
edited your answer- –  sircapsalot Sep 9 '13 at 17:44
I would recommend setting up the client in a initializer, instead of each request. –  nicooga Sep 9 '13 at 17:54
add comment

Your Answer


