Group code for the poll callout together

Some of the code was in its own component, while some of the code
remained in the polls/show view.

Note that we're re-structuring the code a little bit, so it's clear that
the "already voted" messages are only shown when users can vote. Also
note that now the `can?` condition involves the existence of a
`current_user` and that the poll is not expired, so we can simplify the
`voted_in_web` condition.
This commit is contained in:
Javi Martín
2025-07-09 13:45:48 +02:00
parent 5402cb6042
commit b48682e3e4
2 changed files with 11 additions and 15 deletions

View File

@@ -1,4 +1,14 @@
<% unless can?(:answer, poll) %> <% if can?(:answer, poll) %>
<% if poll.voted_in_booth?(current_user) %>
<div class="callout warning">
<%= t("polls.show.already_voted_in_booth") %>
</div>
<% elsif poll.voted_in_web?(current_user) %>
<div class="callout warning">
<%= t("polls.show.already_voted_in_web") %>
</div>
<% end %>
<% else %>
<% if current_user.nil? %> <% if current_user.nil? %>
<div class="callout primary"> <div class="callout primary">
<%= sanitize(t("polls.show.cant_answer_not_logged_in", <%= sanitize(t("polls.show.cant_answer_not_logged_in",

View File

@@ -17,20 +17,6 @@
<div class="row margin"> <div class="row margin">
<div class="small-12 medium-9 column"> <div class="small-12 medium-9 column">
<%= render Polls::CalloutComponent.new(@poll) %> <%= render Polls::CalloutComponent.new(@poll) %>
<% if @poll.voted_in_booth?(current_user) %>
<div class="callout warning">
<%= t("polls.show.already_voted_in_booth") %>
</div>
<% else %>
<% if current_user && @poll.voted_in_web?(current_user) && !@poll.expired? %>
<div class="callout warning">
<%= t("polls.show.already_voted_in_web") %>
</div>
<% end %>
<% end %>
<%= render Polls::FormComponent.new(@web_vote) %> <%= render Polls::FormComponent.new(@web_vote) %>
</div> </div>
</div> </div>