This file contains 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
# assume we have a :data attribute (an hstore hash) in our model that values have html | |
# data :hstore default({}), not null | |
validate :invalid_html? | |
def invalid_html? | |
self.data.each do |key, value| | |
doc = Nokogiri::HTML(value) {|config| config.strict } | |
if doc.errors.any? | |
errors.add(:base, "#{key}: #{doc.errors.join(", ")}") | |
end | |
end | |
end | |
# The problem is that Nokogiri its NOT very :strict | |
#2.1.3 :001 > Nokogiri::HTML("<a/><a/><a/>") {|config| config.strict }.errors.any? | |
# => false | |
2.1.3 :002 > |
No comments:
Post a Comment