/
relevances_controller.rb
41 lines (35 loc) · 1.12 KB
/
relevances_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# encoding: utf-8
class RelevancesController < ApplicationController
respond_to :html, :js
before_action :authenticate_account!
before_action :load_comment
def for
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: notice, nb_votes: current_account.nb_votes } }
wants.html { redirect_back fallback_location: root_url }
end
end
def against
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: notice, nb_votes: current_account.nb_votes } }
wants.html { redirect_back :back fallback_location: root_url }
end
end
protected
def load_comment
@comment = Comment.find(params[:id])
Rails.logger.info "Relevance on #{params[:id]} #{params[:action]} by #{current_user.id} #{request.remote_ip} at #{Time.now.to_i}"
end
end