Sha256: 71008a1f9bb589b59aac93ef9e4c06329e6a64e27bf3dee85cae716e76091eb0
Contents?: true
Size: 762 Bytes
Versions: 47
Compression:
Stored size: 762 Bytes
Contents
# frozen_string_literal: true # This validator takes care of ensuring the validated content is # an existing address and computes its coordinates. class GeocodingValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) if Decidim.geocoder.present? && record.feature.present? organization = record.feature.organization Geocoder.configure(Geocoder.config.merge(http_headers: { "Referer" => organization.host })) coordinates = Geocoder.coordinates(value) if coordinates.present? record.latitude = coordinates.first record.longitude = coordinates.last else record.errors.add(attribute, :invalid) end else record.errors.add(attribute, :invalid) end end end
Version data entries
47 entries across 47 versions & 2 rubygems