diff --git a/app/controllers/votes_controller.rb b/app/controllers/votes_controller.rb index e93968f35..c42935ddf 100644 --- a/app/controllers/votes_controller.rb +++ b/app/controllers/votes_controller.rb @@ -1,21 +1,38 @@ class VotesController < ApplicationController before_action :set_debate + before_action :set_resource 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") respond_with @debate end private + def set_resource + @resource = resource_model.find(params["#{resource_name + "_id"}"]) + end + + def resource_name + @resource_name ||= params[:votable_type] + end + + def resource_model + resource_name.capitalize.constantize + end + def set_debate @debate = Debate.find(params[:debate_id]) end def register_vote - @debate.vote_by voter: current_user, vote: params[:value] + @resource.vote_by voter: current_user, vote: params[:value] end + + def notice + @resource.vote_registered? ? I18n.t("votes.notice_thanks") : I18n.t("votes.notice_already_registered") + end + end diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 0d152d928..50c033670 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -8,6 +8,11 @@ <%= comment.user.name %> • <%= time_ago_in_words(comment.created_at) %>
<%= comment.body %>
+ + + <%= render 'comments/votes', comment: comment %> + +<%= render 'comments/form', parent: comment %>
diff --git a/app/views/comments/_votes.html.erb b/app/views/comments/_votes.html.erb new file mode 100644 index 000000000..24b7dd869 --- /dev/null +++ b/app/views/comments/_votes.html.erb @@ -0,0 +1,11 @@ + + <%= link_to "up", debate_comment_votes_path(@debate, comment, value: 'yes'), + method: "post", remote: true %> + <%= comment.get_likes.size %> + + + + <%= link_to "down", debate_comment_votes_path(@debate, comment, value: 'no'), + method: "post", remote: true %> + <%= comment.get_dislikes.size %> + \ No newline at end of file diff --git a/app/views/votes/_votes.html.erb b/app/views/debates/_votes.html.erb similarity index 100% rename from app/views/votes/_votes.html.erb rename to app/views/debates/_votes.html.erb diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 3ae0cace4..8ea945eee 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -17,8 +17,8 @@<%= render 'shared/tags', debate: @debate %>
-