app/controllers/ratings_controller.rb
#filters the description to make sure that inappropriate words are not present.
filters the description to make sure that inappropriate words are not present.
filters the description to make sure that inappropriate words are not present .
def filter 
      hate_filter = LanguageFilter::Filter.new(matchlist: :hate, exceptionlist: [], replacement: :vowels) 
      profanity_filter = LanguageFilter::Filter.new(matchlist: :profanity, exceptionlist: [], replacement: :vowels) 
      violence_filter = LanguageFilter::Filter.new(matchlist: :violence, exceptionlist: [], replacement: :vowels) 
      if profanity_filter.match?(@rating.description) 
        flash[:warning] = "Your post has been sanitized for the following profane language: #{profanity_filter.matched(@rating.description)}."
        @rating.description = profanity_filter.sanitize(@rating.description)
        @rating.save 
      elsif hate_filter.match?(@rating.description) 
        flash[:warning] = "Your post has been sanitized for the following hate language: #{hate_filter.matched(@rating.description)}."
        @rating.description = hate_filter.sanitize(@rating.description)
        @rating.save 
      elsif violence_filter.match?(@rating.description)
        flash[:warning] = "Your post has been sanitized for the following violent language: #{violence_filter.matched(@rating.description)}."
        @rating.description = violence_filter.sanitize(@rating.description)
        @rating.save 
      else
      end
    end
def filter hate_filter = LanguageFilter :: Filter . new ( matchlist : :hate , exceptionlist : [ ] , replacement : :vowels ) profanity_filter = LanguageFilter :: Filter . new ( matchlist : :profanity , exceptionlist : [ ] , replacement : :vowels ) violence_filter = LanguageFilter :: Filter . new ( matchlist : :violence , exceptionlist : [ ] , replacement : :vowels ) if profanity_filter . match? ( @rating . description ) flash [ :warning ] = "Your post has been sanitized for the following profane language: #{profanity_filter.matched(@rating.description)}." @rating . description = profanity_filter . sanitize ( @rating . description ) @rating . save elsif hate_filter . match? ( @rating . description ) flash [ :warning ] = "Your post has been sanitized for the following hate language: #{hate_filter.matched(@rating.description)}." @rating . description = hate_filter . sanitize ( @rating . description ) @rating . save elsif violence_filter . match? ( @rating . description ) flash [ :warning ] = "Your post has been sanitized for the following violent language: #{violence_filter.matched(@rating.description)}." @rating . description = violence_filter . sanitize ( @rating . description ) @rating . save else end end
filters the description to make sure that inappropriate words are not present.
filters the description to make sure that inappropriate words are not present .