Skip to content

Instantly share code, notes, and snippets.

@JakeAustwick
Created October 25, 2011 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JakeAustwick/1313254 to your computer and use it in GitHub Desktop.
Save JakeAustwick/1313254 to your computer and use it in GitHub Desktop.
class Comment < ActiveRecord::Base
include Sanitize
belongs_to :picture
validates :name, :presence => true
validates :comment, :presence => true, :length => { :in => 5..300 }
before_save :strip_html
private
def strip_html
self.name = Sanitize.clean(self.name) # Strips all HTML
self.comment = Sanitize.clean(self.comment, Sanitize::Config::BASIC) # Add nofollow to avoid spam, and allows basic formatting.
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment