Browse files

Worked on adding errors when there are mispellings

  • Loading branch information...
1 parent 4fa1c96 commit 327500f401d55778166358d285b52c581516f619 David Davis committed Feb 21, 2011
Showing with 19 additions and 2 deletions.
  1. +13 −1 app/controllers/posts_controller.rb
  2. +6 −0 app/views/layouts/application.html.erb
  3. +0 −1 lib/rack/spellcheck.rb
View
14 app/controllers/posts_controller.rb
@@ -43,7 +43,7 @@ def create
@post = Post.new(params[:post])
respond_to do |format|
- if @post.save
+ if check_spelling && @post.save
format.html { redirect_to(@post, :notice => 'Post was successfully created.') }
format.xml { render :xml => @post, :status => :created, :location => @post }
else
@@ -80,4 +80,16 @@ def destroy
format.xml { head :ok }
end
end
+
+ def check_spelling
+ if session[:mispellings].any?
+ post = session[:mispellings]["post"]
+ post.each do |key, value|
+ next if value.length < 1
+ @post.errors.add(:base, "You mispelled '#{value.join("', '")}' in the #{key} field")
+ end
+ return @post.errors.empty?
+ end
+ return true
+ end
end
View
6 app/views/layouts/application.html.erb
@@ -8,6 +8,12 @@
</head>
<body>
+<% flash.each do |key, value| %>
+ <p style='<%= key == :alert ? "color: red" : "" %>'>
+ <%= value %>
+ </p>
+<% end -%>
+
<%= yield %>
</body>
View
1 lib/rack/spellcheck.rb
@@ -1,6 +1,5 @@
module Rack
class Spellcheck
-
DICTIONARIES = "doc/en_US,doc/en_US_OpenMedSpel"
def initialize(app, ignored_fields = nil)

0 comments on commit 327500f

Please sign in to comment.