Implements answers in a partial
This commit is contained in:
@@ -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
|
||||
|
||||
23
app/views/poll/questions/_answers.html.erb
Normal file
23
app/views/poll/questions/_answers.html.erb
Normal 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>
|
||||
@@ -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 %>
|
||||
|
||||
Reference in New Issue
Block a user