* Clean up javascript.
* Return HTTP 422 instead of HTTP 500 on "you have already voted for
this post" errors.
* In json/xml error responses, return the error message in the `message`
field, not `reason`.
* In json/xml success responses, return the post itself instead of a
plain `{ success: true }` object.
21 lines
408 B
Ruby
21 lines
408 B
Ruby
class PostVotesController < ApplicationController
|
|
before_action :voter_only
|
|
skip_before_action :api_check
|
|
respond_to :js, :json, :xml
|
|
rescue_with PostVote::Error, status: 422
|
|
|
|
def create
|
|
@post = Post.find(params[:post_id])
|
|
@post.vote!(params[:score])
|
|
|
|
respond_with(@post)
|
|
end
|
|
|
|
def destroy
|
|
@post = Post.find(params[:post_id])
|
|
@post.unvote!
|
|
|
|
respond_with(@post)
|
|
end
|
|
end
|