0

I am using Ruby Geocoder with Rails. I have the following in my model:

class Location < ActiveRecord::Base
  geocoded_by :locale

  def locale
    [city, state].compact.join(', ')
  end

  before_save :geocode #, :if => :address_changed?
end

I have a rake task that imports cities & states into the locations database. However, as it is running, it throws the following error constantly:

Google Geocoding API error: over query limit.

The Geocoder docs offer this option for the rake task to alleviate the problem:

rake geocode:all CLASS=YourModel SLEEP=0.25 BATCH=100

How would I put an option like that in the before_save callback in my model?

Choylton B. Higginbottom
  • 2,236
  • 3
  • 24
  • 34
  • Why can't you just put a sleep statement in your rake task? – Sunil D. May 25 '15 at 19:09
  • I'm trying to use it automatically in the before_save callback rather than having to manually run a rake task. – Choylton B. Higginbottom May 25 '15 at 19:11
  • Putting it in the before_save callback means it would sleep anytime you save the model, even when you're saving a single object. Insert the delay in the place that you are looping over the model objects. That seems to be your rake task that imports the data. – Sunil D. May 25 '15 at 19:13

0 Answers0