Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. class Article < ActiveRecord::Base
  2. before_save :anti_spam
  3.  
  4. validates_presence_of :title
  5. validates_presence_of :body
  6.  
  7. def anti_spam
  8. doc = Nokogiri::HTML::DocumentFragment.parse(body)
  9.  
  10. doc.css('a').each do |a|
  11. a[:rel] = 'nofollow'
  12. a[:target] = '_blank'
  13. end
  14.  
  15. self.body = doc.to_s
  16. end
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement