You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Users are unable to remove a vote once they've hit their vote quota since the controller protection doesn't let them save any vote (even a vote cancellation) if quota hit. The key reason this is happening is the call of current_user.has_votes_remaining? as the if-check on the def vote function:
class VotesController < ApplicationController
before_filter :authenticate_user!
def vote
if params[:vote][:research_topic_id] and current_user.can_vote_for?(ResearchTopic.find(params[:vote][:research_topic_id])) and current_user.has_votes_remaining?
My monkey patch was to change the if-check to "....and (current_user.has_votes_remaining? || params[:vote][:rating] == "0")". But it's unelegant and exposes too much underlying implementation in the controller. And reeks of a minor refactor to a better solution.
def vote
if params[:vote][:research_topic_id] and current_user.can_vote_for?(ResearchTopic.find(params[:vote][:research_topic_id])) and (current_user.has_votes_remaining? || params[:vote][:rating] == "0")
The text was updated successfully, but these errors were encountered:
Users are unable to remove a vote once they've hit their vote quota since the controller protection doesn't let them save any vote (even a vote cancellation) if quota hit. The key reason this is happening is the call of current_user.has_votes_remaining? as the if-check on the def vote function:
class VotesController < ApplicationController
before_filter :authenticate_user!
def vote
if params[:vote][:research_topic_id] and current_user.can_vote_for?(ResearchTopic.find(params[:vote][:research_topic_id])) and current_user.has_votes_remaining?
My monkey patch was to change the if-check to "....and (current_user.has_votes_remaining? || params[:vote][:rating] == "0")". But it's unelegant and exposes too much underlying implementation in the controller. And reeks of a minor refactor to a better solution.
def vote
if params[:vote][:research_topic_id] and current_user.can_vote_for?(ResearchTopic.find(params[:vote][:research_topic_id])) and (current_user.has_votes_remaining? || params[:vote][:rating] == "0")
The text was updated successfully, but these errors were encountered: