Implements answers in a partial

This commit is contained in:
kikito
2016-11-11 19:10:11 +01:00
parent 63311d6cd1
commit 0c9e6db04d
3 changed files with 36 additions and 9 deletions

View File

@@ -9,10 +9,14 @@ class PollsController < ApplicationController
end
def show
questions = @poll.questions.sort_for_list.for_render
@answerable_questions = @poll.questions.answerable_by(current_user).for_render.sort_for_list
@non_answerable_questions = @poll.questions.where.not(id: @answerable_questions.map(&:id)).for_render.sort_for_list
@answerable_questions = questions.answerable_by(current_user)
@non_answerable_questions = questions.where.not(id: @answerable_questions.pluck(:id))
@answers_by_question_id = {}
poll_partial_results = Poll::PartialResult.by_question(@poll.question_ids).by_author(current_user.try(:id))
poll_partial_results.each do |result|
@answers_by_question_id[result.question_id] = result.answer
end
end
end

View File

@@ -0,0 +1,23 @@
<div class="enquiries-answers">
<% if can? :answer, question %>
<div class="small-12 small-centered text-center column">
<% question.valid_answers.each do |answer| %>
<% if @answers_by_question_id[question.id] == answer %>
<span class="button answered-fixme-decabeza">
<%= answer %>
</span>
<% else %>
<%= link_to answer,
answer_poll_question_path(poll_id: question.poll_id, question_id: question.id, answer: answer),
method: :post,
remote: true,
class: "button secondary hollow" %>
<% end %>
<% end %>
</div>
<% else %>
<% question.valid_answers.each do |answer| %>
<span class="button deactivated-fixme-decabeza"><%= answer %></span>
<% end %>
<% end %>
</div>

View File

@@ -29,9 +29,9 @@
<div id="<%= dom_id(question) %>">
<%= question.title %>
<% question.valid_answers.each do |valid_answer| %>
<%= link_to valid_answer %>
<% end %>
<div class="row margin-top text-center" id="<%= dom_id(question) %>_answers">
<%= render 'poll/questions/answers', question: question %>
</div>
</div>
<% end %>
@@ -46,8 +46,8 @@
<div id="<%= dom_id(question) %>">
<%= question.title %>
<% question.valid_answers.each do |valid_answer| %>
<span><%= valid_answer %></span>
<% end %>
<div class="row margin-top text-center" id="<%= dom_id(question) %>_answers">
<%= render 'poll/questions/answers', question: question %>
</div>
</div>
<% end %>