Class: SlimValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- SlimValidator
- Defined in:
- lib/slim_validation.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attr_name, value) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/slim_validation.rb', line 7 def validate_each(record, attr_name, value) result = Slim::Template.new([:options]) { value }.render([:scope] == :record ? record : [:scope]) rescue => e if (error_storer = [:error]).present? record.send("#{error_storer}=", e) end record.errors.add(attr_name, :invalid_slim, ) ensure if (to = [:to]).present? to.is_a?(Proc) ? to.(record, result) : record.send("#{to}=", result) end end |