-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge scope contraints for comments and votes routes
- Loading branch information
Osmond Oscar
committed
Feb 18, 2016
1 parent
0501f56
commit 1bc6fb5
Showing
2 changed files
with
5 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
class VotesController < ApplicationController | ||
def upvote | ||
resource_to_upvote = vote_params[:resource_name].singularize.camelize.constantize | ||
vote = Vote.act_on_vote('plus', resource_to_upvote, vote_params[:id], current_user) | ||
vote = Vote.act_on_vote('plus', resource_to_upvote, vote_params[:resource_id], current_user) | ||
render json: { response: vote }, status: 200 unless vote.nil? | ||
render json: { error: "Invalid vote!" }, status: 403 if vote.nil? | ||
end | ||
|
||
def downvote | ||
resource_to_upvote = vote_params[:resource_name].singularize.camelize.constantize | ||
vote = Vote.act_on_vote('minus', resource_to_upvote, vote_params[:id], current_user) | ||
vote = Vote.act_on_vote('minus', resource_to_upvote, vote_params[:resource_id], current_user) | ||
render json: { response: vote }, status: 200 unless vote.nil? | ||
render json: { error: "Invalid vote!" }, status: 403 if vote.nil? | ||
end | ||
|
||
private | ||
def vote_params | ||
params.permit(:resource_name, :id) | ||
params.permit(:resource_name, :resource_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters