blob: 8754b91e9bd59917d63f472b477c025b3add762f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
class ScoresController < ApplicationController
allow_unauthenticated_access
before_action :set_tartiflette, only: [:new, :create, :edit_all, :update_all]
def new
end
def create
handle_scoring(:submit_scores, "enregistrement")
end
def edit_all
@scores = @tartiflette.scores
end
def update_all
handle_scoring(:update_scores, "mise à jour")
end
private
def set_tartiflette
@tartiflette = Tartiflette.find(params[:tartiflette_id])
end
def scores_params
params.require(:scores).permit!.to_h
end
def handle_scoring(service_method, action)
TartifletteScoringService.send(service_method, @tartiflette, scores_params, session)
redirect_to root_path, notice: "Vos scores pour la tartiflette #{@tartiflette.scoring_id} ont été #{action}."
rescue StandardError => e
handle_error("Erreur lors de #{action} de vos scores : #{e.message}")
end
def handle_error(message)
redirect_to root_path, status: :unprocessable_entity, alert: message
end
end
|