Skip to content

Instantly share code, notes, and snippets.

@benoror
Created June 2, 2011 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benoror/1003882 to your computer and use it in GitHub Desktop.
Save benoror/1003882 to your computer and use it in GitHub Desktop.
City Validator for Metropoli (github.com/innku/metropoli)
# lib/validators/metropoli_city_validator.rb
class MetropoliCityValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors[:base] << 'Ciudad no valida' if Metropoli::CityModel.with_values(value).empty?
end
end
# app/models/some_model.rb
class SomeModel < ActiveRecord::Base
# ...
validates :city_name, :presence => true, :metropoli_city => true
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment