Commits

Anonymous committed 3e58936

* Updated schema
* Removed AlreadyVotedError exception, rely on boolean returns instead

Comments (0)

Files changed (3)

app/controllers/api_controller.rb

 			return
 		end
 
-		begin
-			p.vote!(score, @request.remote_ip)
+		if p.vote!(score, @request.remote_ip)
 			render :nothing => true
-		rescue Post::AlreadyVotedError
+		else Post::AlreadyVotedError
 			render :text => "already voted", :status => 500
 		end
 	end
     id integer NOT NULL,
     name text NOT NULL,
     "password" text NOT NULL,
-    "level" integer DEFAULT 0 NOT NULL
+    "level" integer DEFAULT 0 NOT NULL,
+	login_count integer DEFAULT 0 NOT NULL
 );
 
 

vendor/plugins/votable/lib/votable.rb

 		def votable(options = {})
 			class_eval do
 				include Votable::InstanceMethods
-
-				class AlreadyVotedError < Exception; end
 			end
 		end
 	end
 	module InstanceMethods
 		def vote!(score, ip_addr)
 			if self.last_voter_ip == ip_addr
-				raise AlreadyVotedError
+				return false
 			else
 				self.update_attributes(:score => self.score + score, :last_voter_ip => ip_addr)
 			end
+
+			return true
 		end
 	end
 end