Skip to content

Instantly share code, notes, and snippets.

@hugoerg56
Created December 14, 2016 20:02
Show Gist options
  • Save hugoerg56/cb2ccb2d4aa8945fd53051e8ec4f4023 to your computer and use it in GitHub Desktop.
Save hugoerg56/cb2ccb2d4aa8945fd53051e8ec4f4023 to your computer and use it in GitHub Desktop.
list_of_valid_states = ["Alava", "Albacete"....]
class OptionsValidator < ActiveModel::Validator
def validate(record)
unless list_of_valid_states.include?(record.state)
record.errors[:state] << 'This is not a valid state!'
end
end
end
class MiModelo
include ActiveModel::Validations
validates_with OptionsValidator
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment