Sha256: 5e3c1c6857f24e55f5756546a535f5c157c8f5807d43cf146f593baad1bedb28
Contents?: true
Size: 766 Bytes
Versions: 30
Compression:
Stored size: 766 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.component.present? organization = record.component.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
30 entries across 30 versions & 1 rubygems