docbrown/app/controllers/rating_votes_controller.rb
Ben Halpern 532903c688
Add experience level averaging to articles (#1922)
* Add experience level averaging to articles

* Adjust copy on /mod ratings page
2019-02-28 08:17:29 -08:00

24 lines
788 B
Ruby

class RatingVotesController < ApplicationController
after_action :verify_authorized
def create
authorize RatingVote
rating_vote = RatingVote.where(user_id: current_user.id, article_id: rating_vote_params[:article_id]).first || RatingVote.new
rating_vote.user_id = current_user.id
rating_vote.article_id = rating_vote_params[:article_id]
rating_vote.rating = rating_vote_params[:rating].to_f
rating_vote.group = rating_vote_params[:group]
if rating_vote.save
rating_vote.assign_article_rating
redirect_back(fallback_location: "/mod")
else
render json: { result: "Not Upserted Successfully" }
end
end
private
def rating_vote_params
params.require(:rating_vote).permit(policy(RatingVote).permitted_attributes)
end
end