2 # validation method to be included like any other validations methods
3 # in the models definitions. this one checks that the named attribute
4 # is a valid UTF-8 format string.
5 class Utf8Validator < ActiveModel::EachValidator
6 def validate_each(record, attribute, value)
7 record.errors.add(attribute, " is invalid UTF-8") unless UTF8.valid? value