Skip to content

Instantly share code, notes, and snippets.

View gbarrancos's full-sized avatar

Gustavo Barrancos gbarrancos

  • Nubank
  • São Paulo - Brazil
View GitHub Profile
# in the model
validates_with CoordinatesValidator, :fields => [:location]
# Error messaging needs improvement. Since this validator will only whine if someone is forging requests
# with invalid data, i'm leaving it as it is.
class CoordinatesValidator < ActiveModel::Validator
def validate(record)
if options[:fields].any? { |f| invalid_latlng?(record.send(f)) }