Class: LiquidValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/validators/liquid_validator.rb

Overview

An ActiveRecord validator for any liquid field that you would use with effective_email_templates or otherwise

validates :body, liquid: true

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/validators/liquid_validator.rb', line 6

def validate_each(record, attribute, value)
  if value.present?
    begin
      Liquid::Template.parse(value)
    rescue Liquid::SyntaxError => e
      record.errors.add(attribute, e.message)
    end
  end
end