Rails Geocoding Using City and State Address

I am using rails geocoder gem and have the following in my location model

geocoded_by :address

      

but my location has other attributes like city, state and country that affect the displayed address.

How to geocode through all 4 inputs? I tried to create a full_address variable with all 4 attributes, but I don't know where this is going.

Thank!

+3


source to share


1 answer


Instead of a variable, you can use a method that will map these attributes into a single string, for example:

def full_street_address
  [address, city, state, country].compact.join(', ')
end

      



Then you can simply change the geocoded_by line to:

geocoded_by :full_street_address

      

+12


source







All Articles