diff --git a/app/controllers/comment_votes_controller.rb b/app/controllers/comment_votes_controller.rb index 7fd3176aa..101a5ab02 100644 --- a/app/controllers/comment_votes_controller.rb +++ b/app/controllers/comment_votes_controller.rb @@ -7,4 +7,11 @@ class CommentVotesController < ApplicationController @comment_vote = @comment.vote!(params[:score]) respond_with(@comment_vote) end + + def destroy + @comment = Comment.find(params[:comment_id]) + @comment.unvote!(params[:score]) + rescue CommentVote::Error => x + @error = x + end end diff --git a/app/controllers/post_votes_controller.rb b/app/controllers/post_votes_controller.rb index 88d81ecad..e4c8071fa 100644 --- a/app/controllers/post_votes_controller.rb +++ b/app/controllers/post_votes_controller.rb @@ -8,6 +8,13 @@ class PostVotesController < ApplicationController @error = x end + def destroy + @post = Post.find(params[:post_id]) + @post.unvote! + rescue PostVote::Error => x + @error = x + end + protected def voter_only diff --git a/app/views/comment_votes/destroy.json.erb b/app/views/comment_votes/destroy.json.erb new file mode 100644 index 000000000..052990686 --- /dev/null +++ b/app/views/comment_votes/destroy.json.erb @@ -0,0 +1,5 @@ +<% if @error %> + {"success": false, "reason": <%= @error.to_s.to_json.html_safe %>} +<% else %> + {"success": true} +<% end %> diff --git a/app/views/comment_votes/destroy.xml.erb b/app/views/comment_votes/destroy.xml.erb new file mode 100644 index 000000000..46666469e --- /dev/null +++ b/app/views/comment_votes/destroy.xml.erb @@ -0,0 +1,6 @@ + +<% if @error %> + <%= @error.to_s %> +<% else %> + +<% end %> diff --git a/app/views/post_votes/destroy.json.erb b/app/views/post_votes/destroy.json.erb new file mode 100644 index 000000000..052990686 --- /dev/null +++ b/app/views/post_votes/destroy.json.erb @@ -0,0 +1,5 @@ +<% if @error %> + {"success": false, "reason": <%= @error.to_s.to_json.html_safe %>} +<% else %> + {"success": true} +<% end %> diff --git a/app/views/post_votes/destroy.xml.erb b/app/views/post_votes/destroy.xml.erb new file mode 100644 index 000000000..46666469e --- /dev/null +++ b/app/views/post_votes/destroy.xml.erb @@ -0,0 +1,6 @@ + +<% if @error %> + <%= @error.to_s %> +<% else %> + +<% end %>