Skip to content
Browse files

Don't allow a bad word that is a tracked phrase or already in the db

  • Loading branch information...
1 parent 9b9014a commit 85bc80ab773b8b60b4f8bd27b41848c9b0a56637 @aditya aditya committed Apr 27, 2009
Showing with 12 additions and 3 deletions.
  1. +3 −2 app/controllers/badwords_controller.rb
  2. +7 −0 app/models/badword.rb
  3. +2 −1 app/views/layouts/base.html.erb
View
5 app/controllers/badwords_controller.rb
@@ -47,11 +47,12 @@ def create
respond_to do |format|
if @badword.save
- flash[:notice] = 'Badword was successfully created.'
+ flash[:notice] = 'Skipped Phrase was successfully created.'
format.html { redirect_to(badwords_url) }
format.xml { render :xml => @badword, :status => :created, :location => @badword }
else
- format.html { render :action => "index" }
+ flash[:notice] = 'Skipped Phrase creation failed'
+ format.html { redirect_to(badwords_url) }
format.xml { render :xml => @badword.errors, :status => :unprocessable_entity }
end
end
View
7 app/models/badword.rb
@@ -2,4 +2,11 @@ class Badword < ActiveRecord::Base
set_table_name "blacklist"
validates_presence_of :term
+ validates_uniqueness_of :term
+
+ before_save :dont_save_phrases
+
+ def dont_save_phrases
+ return false if Phrase.find_by_title(self.term)
+ end
end
View
3 app/views/layouts/base.html.erb
@@ -16,6 +16,7 @@
</head>
<body>
<div class="wrapper">
+ <p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
<style>
body
@@ -43,4 +44,4 @@
<noscript><p><img alt="Clicky" width="1" height="1" src="http://static.getclicky.com/81343-db10.gif" /></p></noscript>
<%- end -%>
</body>
-</html>
+</html>

0 comments on commit 85bc80a

Please sign in to comment.
Something went wrong with that request. Please try again.