Created
June 9, 2015 15:15
-
-
Save rikkipitt/4551c9b72b35cd7a4756 to your computer and use it in GitHub Desktop.
Dentaku expression validator
This file contains 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
class ExpressionValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
begin | |
Dentaku(value) | |
rescue Exception => e | |
record.errors[attribute] << (options[:message] || e.message) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For use with Dentaku.
Save to
app/validators/expression_validator.rb
and include in your model like so: