Skip to content
Olli Huotari edited this page Mar 24, 2018 · 11 revisions

AutoStripAttributes Custom Filter Recipes

The gem is kept small and simple by choice. See the manual at https://github.com/holli/auto_strip_attributes/ .

This page includes some custom filters that were not included in the gem as options but might otherwise be helpful. See https://github.com/holli/auto_strip_attributes#custom-filters for more info.

Titleize

AutoStripAttributes::Config.setup do
  set_filter :titleize => false do |value|
    !value.blank? && value.respond_to?(:titleize) ? value.titleize : value
  end
end

Removing utf8 4 bit chars

Good if you are using Mysql utf8 columns in database instead of utf8mb4

AutoStripAttributes::Config.setup do
  set_filter :strip_4_byte_chars => false do |value|
    !value.blank? && value.respond_to?(:each_char) ? value.each_char.select{|c| c.bytes.count < 4 }.join('') : value
  end
end
Clone this wiki locally