Module: Hippo::Concerns::SanitizeFields::ClassMethods

Defined in:
lib/hippo/concerns/sanitize_fields.rb

Instance Method Summary collapse

Instance Method Details

#sanitize_fields(*fields) ⇒ Object

Remove invalid HTML from fields before save by using the “sanitize” gem's Sanitize.fragment method.

Defaults to removing all HTML, but a valid Sanitize::Config hash can be specified as well.


16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/hippo/concerns/sanitize_fields.rb', line 16

def sanitize_fields(*fields)
    options = fields.extract_options!
    using = options[:using] || {}
    before_save do
        fields.each do |field|
            value = read_attribute(field)
            unless value.blank?
                write_attribute(field, Sanitize.fragment(sanitized,using))
            end
        end
    end
end