-
-
Save jonpaul/1136903 to your computer and use it in GitHub Desktop.
Sanitize class macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActiveRecord::Base | |
def self.sanitize_attribute(*attr_names) | |
attr_names.each do |attr_name| | |
define_method attr_name do | |
self[attr_name].try(:html_safe) | |
end | |
define_method "#{attr_name}=" do |attr_value| | |
self[attr_name] = attr_value.try(:sanitize) | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def sanitize() | |
Sanitize.clean(self, Sanitize::Config::RELAXED).strip.html_safe | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment