responds with ajax to debate vote [#47]

This commit is contained in:
rgarcia
2015-07-28 20:52:59 +02:00
parent be2a481cd7
commit bdcd513f26
4 changed files with 29 additions and 24 deletions

View File

@@ -1,11 +1,12 @@
class VotesController < ApplicationController
before_action :set_debate
before_action :authenticate_user!
respond_to :html, :js
def create
register_vote
notice = @debate.vote_registered? ? I18n.t("votes.notice_thanks") : I18n.t("votes.notice_already_registered")
redirect_to @debate, notice: notice
respond_with @debate
end
private

View File

@@ -10,28 +10,8 @@
<p><%= render 'shared/tags', debate: @debate %></p>
</div>
<div class="votes small-12 medium-3 column">
<div class="small-12 column text-center">
<div id="in_favor" class="inline-block">
<%= link_to debate_votes_path(@debate, value: 'yes'), :class => 'in-favor', method: "post" do %>
<i class="fi-like"></i>
<span><%= percentage('likes', @debate) %></span>
<% end %>
</div>
<span class="divider"></span>
<div id="against" class="inline-block">
<%= link_to debate_votes_path(@debate, value: 'no'), :class => 'against', method: "post" do %>
<i class="fi-dislike"></i>
<span><%= percentage('dislikes', @debate) %></span>
<% end %>
</div>
</div>
<div class="small-12 column text-center">
<p class="total-votes"><%= pluralize(@debate.total_votes, t("debates.debate.vote"), t("debates.debate.votes")) %></p>
</div>
<div id="votes" class="votes small-12 medium-3 column">
<%= render 'votes/vote' %>
</div>
</div>

View File

@@ -0,0 +1,23 @@
<div class="small-12 column text-center">
<div id="in_favor" class="inline-block">
<%= link_to debate_votes_path(@debate, value: 'yes'), class: 'in-favor', method: 'post', remote: true do %>
<i class="fi-like"></i>
<span><%= percentage('likes', @debate) %></span>
<% end %>
</div>
<span class="divider"></span>
<div id="against" class="inline-block">
<%= link_to debate_votes_path(@debate, value: 'no'), class: 'against', method: 'post', remote: true do %>
<i class="fi-dislike"></i>
<span><%= percentage('dislikes', @debate) %></span>
<% end %>
</div>
</div>
<div class="small-12 column text-center">
<p class="total-votes">
<%= pluralize(@debate.total_votes, t("debates.debate.vote"), t("debates.debate.votes")) %>
</p>
</div>

View File

@@ -0,0 +1 @@
$("#votes").html("<%= j render('vote') %>");