I am creating a cinema site using Ruby on Rails and am adding in a review system. I want to stop users from swearing in their reviews and have tried the following gems to do so:
validates_decency_of
NoNo
Fu-Fu
The only thing that has come close is using exclusion:
validates :review_text, :exclusion => { :in => %w(shit fuck fucking twat bitch), :message => "you must not enter swear words"}
But the problem with this is that it will only work against reviews that have only those words, e.g. if you type "shit film" it will allow it but it will not allow the single word "shit".
Can someone please help.
review.rb:
class Review < ActiveRecord::Base
belongs_to :user
belongs_to :film
validates :review_text, :presence => { :message => "Please enter a review"}
validates :review_text, :length => {:maximum => 2000, :message => "The review must not exceed 2000 characters"}
validates :review_text, length: { maximum: 2000 }
end
Aucun commentaire:
Enregistrer un commentaire