Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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 >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement