responds with ajax to debate vote [#47]
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
23
app/views/votes/_vote.html.erb
Normal file
23
app/views/votes/_vote.html.erb
Normal 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>
|
||||
1
app/views/votes/create.js.erb
Normal file
1
app/views/votes/create.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#votes").html("<%= j render('vote') %>");
|
||||
Reference in New Issue
Block a user