fix(champs): attach piece justificative
This commit is contained in:
parent
d118577564
commit
3400c4c628
1 changed files with 16 additions and 6 deletions
|
@ -2,14 +2,24 @@ class Champs::PieceJustificativeController < ApplicationController
|
||||||
before_action :authenticate_logged_user!
|
before_action :authenticate_logged_user!
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@champ = policy_scope(Champ).find(params[:champ_id])
|
if attach_piece_justificative_or_retry
|
||||||
|
|
||||||
@champ.piece_justificative_file.attach(params[:blob_signed_id])
|
|
||||||
if @champ.save
|
|
||||||
render :show
|
render :show
|
||||||
else
|
else
|
||||||
errors = @champ.errors.full_messages
|
render json: { errors: @champ.errors.full_messages }, status: 422
|
||||||
render :json => { errors: errors }, :status => 422
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def attach_piece_justificative
|
||||||
|
@champ = policy_scope(Champ).find(params[:champ_id])
|
||||||
|
@champ.piece_justificative_file.attach(params[:blob_signed_id])
|
||||||
|
@champ.save
|
||||||
|
end
|
||||||
|
|
||||||
|
def attach_piece_justificative_or_retry
|
||||||
|
attach_piece_justificative
|
||||||
|
rescue ActiveRecord::StaleObjectError
|
||||||
|
attach_piece_justificative
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue