Module: RailsCoreExtensions::ActiveRecordLiquidExtensions::ClassMethods
- Defined in:
- lib/rails_core_extensions/active_record_liquid_extensions.rb
Instance Method Summary collapse
Instance Method Details
#liquid_field(field) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rails_core_extensions/active_record_liquid_extensions.rb', line 17 def liquid_field(field) class_eval <<-CODE def parsed_#{field} Liquid::Template.parse(#{field}) end def render_#{field}(*args) parsed_#{field}.render!(*args) end CODE end |
#validates_liquid(field) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rails_core_extensions/active_record_liquid_extensions.rb', line 6 def validates_liquid(field) field = field.to_sym before_validation do |record| begin Liquid::Template.parse(record.send(field), error_mode: :strict) rescue Liquid::SyntaxError => e record.errors.add(field, "Liquid Syntax Error: #{e}") end end end |