Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

has_votes_remaining? check doesn't work since vote implementation uses ratings of 0 to cancel votes #70

Open
seanahrens opened this issue Oct 7, 2014 · 0 comments
Assignees

Comments

@seanahrens
Copy link
Member

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants