Geocoding multiple addresses in one model

前端 未结 2 770
余生分开走
余生分开走 2021-01-16 08:06

I am trying to geocode 2 addresses in a model using geocoder and I can\'t get gem to work as I want to. Here is the code that I am applying to my model:

clas         


        
2条回答
  •  既然无缘
    2021-01-16 08:36

    Rewrite

    def function
    ...
    end
    

    as:

    def update_coordinates
      geocode
      [latitude, longitude, latitude2, longitude2]
    end
    

    And also:

    geocoded_by :destination_address, :latitude => :latitude2, :longitude => :longitude2
    

    You also don't need :latitude => :lat, :longitude => :lon here:

    geocoded_by :source_address, ...
    

    And finally, coordinates are fetched automatically after record is validated. So you could do without update_coordinates (or function, in your version) and arrange the view for show action like this:

    <%= @sender.latitude %>
    <%= @sender.longitude %>
    <%= @sender.latitude2 %>
    <%= @sender.longitude2 %>
    

提交回复
热议问题