Permalink
Browse files

More spam protection

  • Loading branch information...
1 parent d30e28a commit 069430ff5582dc9e54ecea0d889cf5ef1a47c402 @nakajima committed May 21, 2010
Showing with 19 additions and 6 deletions.
  1. +3 −1 app/models/bookmarklet.rb
  2. +16 −5 app/views/bookmarklets/new.html.erb
@@ -3,8 +3,10 @@ class Bookmarklet < ActiveRecord::Base
validates_presence_of :code
validate :spam_check, :if => :spam?
+ attr_accessor :body # This is for spam detection
+
def spam?
- SpamChecker.new(code).spam?
+ @body || SpamChecker.new(code).spam?
end
private
@@ -7,25 +7,36 @@
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
-
+
<p>
<%= f.label :password, 'Password (optional, but required to edit)' %><br />
<%= f.text_field :password %>
</p>
-
+
<p>
<%= f.label :code %><br />
<%= f.text_area :code %>
</p>
-
+
<p>
<%= f.label :description, 'Description (optional)' %><br />
<%= f.text_area :description %>
</p>
-
+
+ <p class="required">
+ <%= f.label :body, "body" %>
+ <%= f.text_area :body %>
+ </p>
+
+ <script type="text/javascript" charset="utf-8">
+ document.observe('dom:loaded', function() {
+ $$('p.required').invoke('hide'); // spam protection
+ });
+ </script>
+
<p>
<%= f.submit 'Create Bookmarklet' %>
</p>
<% end %>
-<%= link_to 'Back', bookmarklets_path %>
+<%= link_to 'Back', bookmarklets_path %>

0 comments on commit 069430f

Please sign in to comment.