[#835] Extract avis creation into concern
This commit is contained in:
parent
6a43be4f39
commit
31ca0552ab
4 changed files with 35 additions and 17 deletions
26
app/controllers/concerns/create_avis_concern.rb
Normal file
26
app/controllers/concerns/create_avis_concern.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module CreateAvisConcern
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
private
|
||||
|
||||
def create_avis_from_params(dossier, confidentiel = false)
|
||||
confidentiel ||= create_avis_params[:confidentiel]
|
||||
avis = Avis.new(create_avis_params.merge(claimant: current_gestionnaire, dossier: dossier, confidentiel: confidentiel))
|
||||
|
||||
if avis.save
|
||||
flash.notice = "Une demande d'avis a été envoyée à #{avis.email_to_display}"
|
||||
|
||||
nil
|
||||
else
|
||||
flash.now.alert = @avis.errors.full_messages
|
||||
|
||||
# When an error occurs, return the avis back to the controller
|
||||
# to give the user a chance to correct and resubmit
|
||||
avis
|
||||
end
|
||||
end
|
||||
|
||||
def create_avis_params
|
||||
params.require(:avis).permit(:email, :introduction, :confidentiel)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue