2012-02-27 10 views

答えて

3

申し訳ありませんが、遅れている仕事についてどれだけ知っているのか分かりませんので、そこから始めます。

遅延ジョブは '#perform'に応答するすべてのクラスを利用できます。そのため、まず座標を取得してモデルに格納するクラスが必要です。

class GoogleMapsCoordinateService 

    def perform(record) 
    coords = Gmaps4rails.geocode(record.address) #This is the method that will actually return a hash of coordinates for each match it finds. 

    record.update_attributes(:lattitude => coords[0][:lat], :longitude => coords[0][:lng]) 
    end 
end 

次に、あなただけの各レコードが作成された後だから方法は、あなたが座標のグラビングをキューます

class INSERTYOURMODELNAMEHERE < ActiveRecord::Base 

    after_create :get_coordinates 

    def get_coordinates 
    Delayed::Job.enqueue GoogleMapsCoordinateService.new(self) 
    end 
end 

モデルでafter_createフックでそのジョブをキューに入れる必要がありますバックグラウンドであなたの応答時間を素早く保ちます。

+0

あなたを助けてくれてうれしいです。 – TheDelChop

+0

Yeaありがとうございました – Lee

+0

私はこの変数を構造体に入れてこの作業を行う必要がありました: 'class GoogleMapsCoordinateService map7

関連する問題