diff --git a/app/controllers/officing/base_controller.rb b/app/controllers/officing/base_controller.rb index 706ef166c..0ac95364b 100644 --- a/app/controllers/officing/base_controller.rb +++ b/app/controllers/officing/base_controller.rb @@ -13,12 +13,6 @@ class Officing::BaseController < ApplicationController raise CanCan::AccessDenied unless current_user&.poll_officer? end - def check_officer_assignment - if @officer_assignment.blank? - go_back_to_new(t("officing.results.flash.error_wrong_booth")) - end - end - def load_officer_assignment @officer_assignments ||= current_user.poll_officer.officer_assignments.where(date: Time.current.to_date) end diff --git a/app/controllers/officing/results_controller.rb b/app/controllers/officing/results_controller.rb index 4ebd7fba2..21bb8e5f3 100644 --- a/app/controllers/officing/results_controller.rb +++ b/app/controllers/officing/results_controller.rb @@ -38,13 +38,11 @@ class Officing::ResultsController < Officing::BaseController params[:questions].each_pair do |question_id, results| question = @poll.questions.find(question_id) - go_back_to_new if question.blank? results.each_pair do |answer_index, count| next if count.blank? answer = question.question_options.find_by(given_order: answer_index.to_i + 1).title - go_back_to_new if question.blank? partial_result = ::Poll::PartialResult.find_or_initialize_by( booth_assignment_id: @officer_assignment.booth_assignment_id, @@ -79,10 +77,10 @@ class Officing::ResultsController < Officing::BaseController @results << recount end - def go_back_to_new(alert = nil) + def go_back_to_new(alert) params[:d] = Date.current params[:oa] = results_params[:officer_assignment_id] - flash.now[:alert] = (alert || t("officing.results.flash.error_create")) + flash.now[:alert] = alert load_officer_assignments load_partial_results render :new @@ -123,4 +121,10 @@ class Officing::ResultsController < Officing::BaseController def index_params params.permit(:booth_assignment_id, :date) end + + def check_officer_assignment + if @officer_assignment.blank? + go_back_to_new(t("officing.results.flash.error_wrong_booth")) + end + end end diff --git a/config/locales/en/officing.yml b/config/locales/en/officing.yml index 066c137ae..c72ef0b7b 100644 --- a/config/locales/en/officing.yml +++ b/config/locales/en/officing.yml @@ -41,7 +41,6 @@ en: results: flash: create: "Results saved" - error_create: "Results NOT saved. Error in data." error_wrong_booth: "Wrong booth. Results NOT saved." new: title: "%{poll} - Add results" diff --git a/config/locales/es/officing.yml b/config/locales/es/officing.yml index f668ce8a2..7887f6f19 100644 --- a/config/locales/es/officing.yml +++ b/config/locales/es/officing.yml @@ -41,7 +41,6 @@ es: results: flash: create: "Datos guardados" - error_create: "Resultados NO añadidos. Error en los datos" error_wrong_booth: "Urna incorrecta. Resultados NO guardados." new: title: "%{poll} - Añadir resultados"