Force ratings on all candidates before saving

This commit is contained in:
ricola 2025-10-13 20:07:34 +02:00
parent fa57d465be
commit b07b0da672
2 changed files with 35 additions and 5 deletions

View file

@ -1,5 +1,13 @@
<h1><%= @vote.title %></h1>
<% if @errors %>
<% @errors.each do |error| %>
<% if error.attribute == :rating and error.type == :blank %>
<p class="error"><%= _("Missing rating for candidate <i>%{name}</i>." % { name: error.candidate.name }) %></p>
<% end %>
<% end %>
<% end %>
<% if @vote.expire_on %>
<p><%= _("Closing date: %{date}" % { date: format_date_and_time(@vote.expire_on) }) %></p>
<% end %>
@ -12,7 +20,13 @@
<ul>
<% @vote.candidates.each do |candidate| %>
<% rating = @vote.ratings.find { |rating| rating.user == current_user and rating.candidate == candidate } %>
<% value = rating ? rating.value : 0 %>
<% if rating
value = rating.value
elsif @params[candidate.id.to_s]
value = params[candidate.id.to_s].to_i
else
value = 0
end %>
<li>
<p><b><%= candidate.name %></b></p>
<%= markdown(candidate.description) %>