モデルフィールドの住所を変更すると、住所フィールドが更新および保存されても、座標が自動的に更新されないことに気付きました。ジオコードを呼び出す before_save メソッドを作成しました。
before_save :update_location_coordinates # in model being mapped
protected
def update_location_coordinates
place = Gmaps4rails.geocode(gmaps4rails_address).first
self.longitude, self.latitude = place[:lng], place[:lat] unless place.empty?
rescue
nil
end
これは機能しますが、宝石で自動化する必要があるように見えるので、必要かどうか疑問に思っています。何か不足していますか?
ありがとう...
PSジオコードは配列を返すので、最初の(最良の)推測を行いました