Skip to content

Commit

Permalink
Don't let user think they can vote when it's no longer the case
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Jun 16, 2011
1 parent 6c05781 commit 293d220
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
18 changes: 14 additions & 4 deletions app/controllers/relevances_controller.rb
Expand Up @@ -5,17 +5,27 @@ class RelevancesController < ApplicationController
before_filter :load_comment

def for
@comment.vote_for(current_account) if @comment.votable_by?(current_account)
if @comment.votable_by?(current_account)
@comment.vote_for(current_account)
notice = "Merci pour votre vote"
else
notice = "Vote impossible"
end
respond_to do |wants|
wants.json { render :json => { :notice => "Merci pour votre vote", :nb_votes => current_account.nb_votes } }
wants.json { render :json => { :notice => notice, :nb_votes => current_account.nb_votes } }
wants.html { redirect_to :back rescue redirect_to root_url }
end
end

def against
@comment.vote_against(current_account) if @comment.votable_by?(current_account)
if @comment.votable_by?(current_account)
@comment.vote_against(current_account)
notice = "Merci pour votre vote"
else
notice = "Vote impossible"
end
respond_to do |wants|
wants.json { render :json => { :notice => "Merci pour votre vote", :nb_votes => current_account.nb_votes } }
wants.json { render :json => { :notice => notice, :nb_votes => current_account.nb_votes } }
wants.html { redirect_to :back rescue redirect_to root_url }
end
end
Expand Down
18 changes: 14 additions & 4 deletions app/controllers/votes_controller.rb
Expand Up @@ -5,17 +5,27 @@ class VotesController < ApplicationController
before_filter :load_node

def for
@node.vote_for(current_account) if @node.content.votable_by?(current_account)
if @node.content.votable_by?(current_account)
@node.vote_for(current_account)
notice = "Merci pour votre vote"
else
notice = "Vote impossible"
end
respond_to do |wants|
wants.json { render :json => { :notice => "Merci pour votre vote", :nb_votes => current_account.nb_votes } }
wants.json { render :json => { :notice => notice, :nb_votes => current_account.nb_votes } }
wants.html { redirect_to_content @node.content }
end
end

def against
@node.vote_against(current_account) if @node.content.votable_by?(current_account)
if @node.content.votable_by?(current_account)
@node.vote_against(current_account)
notice = "Merci pour votre vote"
else
notice = "Vote impossible"
end
respond_to do |wants|
wants.json { render :json => { :notice => "Merci pour votre vote", :nb_votes => current_account.nb_votes } }
wants.json { render :json => { :notice => notice, :nb_votes => current_account.nb_votes } }
wants.html { redirect_to_content @node.content }
end
end
Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/application.js
Expand Up @@ -3,7 +3,7 @@
if (data && data.notice) {
jQuery.noticeAdd({text: data.notice});
}
if (data && data.nb_votes) {
if (data && data.nb_votes >= 0) {
$("#nb_votes").text(data.nb_votes);
}
if (!$(this).data('hidden')) {
Expand Down

0 comments on commit 293d220

Please sign in to comment.