Advertisement
Guest User

Untitled

a guest
May 29th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. # assume we have a :data attribute (an hstore hash) in our model that values have html
  2. # data :hstore default({}), not null
  3.  
  4. validate :invalid_html?
  5.  
  6. def invalid_html?
  7. self.data.each do |key, value|
  8. doc = Nokogiri::HTML(value) {|config| config.strict }
  9. if doc.errors.any?
  10. errors.add(:base, "#{key}: #{doc.errors.join(", ")}")
  11. end
  12. end
  13. end
  14.  
  15.  
  16. # The problem is that Nokogiri its NOT very :strict
  17. #2.1.3 :001 > Nokogiri::HTML("<a/><a/><a/>") {|config| config.strict }.errors.any?
  18. # => false
  19. 2.1.3 :002 >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement