diff --git a/app/controllers/votes_controller.rb b/app/controllers/votes_controller.rb index 918b852..6643c15 100644 --- a/app/controllers/votes_controller.rb +++ b/app/controllers/votes_controller.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 814c997..8347f19 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,11 +1,8 @@ Rails.application.routes.draw do - scope '/:resource_name/:id', constraints: { resource_name: /(questions|answers|comments)/ } do + scope '/:resource_name/:resource_id', constraints: { resource_name: /(questions|answers|comments)/ } do post '/upvote', to: 'votes#upvote' post '/downvote', to: 'votes#downvote' - end - - scope '/:resource_name/:resource_id', constraints: { resource_name: /(questions|answers)/} do - resources :comments, except: [:new, :edit] + resources :comments, except: [:new, :edit], resource_name: /(?!comments).*/ end post '/validate_token', to: 'tokens#validate'