instructeurs: make the create form not using email directly

Before the form attempted to read an email value from the Instructeur
model, and failed (because the empty Instructeur had no user yet).

We could let `Instructeur#email` return `nil` if there is no User –
but as a created Instructeur is always supposed to have a User, this
seems like a nice safeguard to keep.

So instead this commit rewrites the create form, which now doesn’t
depend on an Instructeur model. Seems easy enough for now.
This commit is contained in:
Pierre de La Morinerie 2019-10-17 14:07:12 +00:00
parent d78d206544
commit f131dbb80d
6 changed files with 11 additions and 16 deletions

View file

@ -25,8 +25,6 @@ class Admin::AssignsController < AdminController
not_assign_scope,
partial: "admin/assigns/list_not_assign",
array: true
@instructeur ||= Instructeur.new
end
def update

View file

@ -7,8 +7,6 @@ class Admin::InstructeursController < AdminController
current_administrateur.instructeurs,
partial: "admin/instructeurs/list",
array: true
@instructeur ||= Instructeur.new
end
def create

View file

@ -9,15 +9,15 @@
%h3
= t('dynamics.admin.procedure.onglet_instructeurs.add.title')
#procedure_new.section.section-label
= form_for @instructeur, url: { controller: 'admin/instructeurs', action: :create } do |f|
= form_with url: { controller: 'admin/instructeurs', action: :create } do
.row
.col-xs-5
= hidden_field_tag :procedure_id, params[:procedure_id]
= render partial: 'admin/instructeurs/informations', locals: { f: f }
= render partial: 'admin/instructeurs/informations'
.col-xs-2
%br
%br
= f.submit 'Valider', class: 'btn btn-info', style: 'float: left;', id: 'add-instructeur-email'
= submit_tag 'Ajouter', class: 'btn btn-info', style: 'float: left;', id: 'add-instructeur-email'
.col-xs-6
%h3.text-success Affectés
= smart_listing_render :instructeurs_assign

View file

@ -1,5 +1,4 @@
- { email: 'Email*' }.each do |key, value|
.form-group
%h4
= value
= f.text_field key, class: 'form-control', placeholder: value
.form-group
%h4
= 'Email *'
= text_field_tag 'instructeur[email]', nil, class: 'form-control', placeholder: 'laura.azema@exemple.gouv.fr'

View file

@ -18,11 +18,11 @@
.col-xs-6
%h3 Ajouter un instructeur
#procedure_new.section.section-label
= form_for @instructeur, url: { controller: 'admin/instructeurs', action: :create } do |f|
= form_with url: { controller: 'admin/instructeurs', action: :create } do
.row
.col-xs-5
= render partial: 'informations', locals: { f: f }
= render partial: 'admin/instructeurs/informations'
.col-xs-2
%br
%br
= f.submit 'Valider', class: 'btn btn-info', style: 'float: left;'
= submit_tag 'Ajouter', class: 'btn btn-info', style: 'float: left;'

View file

@ -12,7 +12,7 @@ feature 'As an instructeur', js: true do
fill_in :instructeur_email, with: instructeur_email
perform_enqueued_jobs do
click_button 'Valider'
click_button 'Ajouter'
end
end