Created
June 2, 2011 03:34
-
-
Save benoror/1003882 to your computer and use it in GitHub Desktop.
City Validator for Metropoli (github.com/innku/metropoli)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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