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

@ -11,6 +11,7 @@ require 'gettext'
require 'securerandom'
require 'chartkick'
require 'mail'
require 'ostruct'
require 'tzinfo'
require 'redcarpet'
@ -386,16 +387,31 @@ post '/votes/:id/reopen' do
redirect '/votes/' + @vote.secure_id
end
get '/votes/:id/ratings' do
redirect '/votes/' + params[:id]
end
post '/votes/:id/ratings' do
require_login
find_vote
require_open_vote
@errors = []
@vote.candidates.each do |candidate|
rating = Rating.find_or_initialize_by(vote: @vote, user: current_user, candidate: candidate)
rating.value = params[candidate.id.to_s]
rating.save
if not params[candidate.id.to_s]
@errors << OpenStruct.new(:attribute => :rating, :type => :blank, :candidate => candidate)
end
end
if not @errors.empty?
@params = params
erb :votes_show_open
else
@vote.candidates.each do |candidate|
rating = Rating.find_or_initialize_by(vote: @vote, user: current_user, candidate: candidate)
rating.value = params[candidate.id.to_s]
rating.save
end
redirect '/votes/' + @vote.secure_id
end
redirect '/votes/' + @vote.secure_id
end
post '/votes/:id/organizers' do