diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb index 839e992ed..c73db4609 100644 --- a/app/controllers/root_controller.rb +++ b/app/controllers/root_controller.rb @@ -75,6 +75,12 @@ class RootController < ApplicationController end @dossier = Dossier.new(champs: all_champs) + all_champs.each do |champ| + champ.association(:dossier).target = @dossier + champ.champs.each do |champ| + champ.association(:dossier).target = @dossier + end + end end def suivi diff --git a/app/helpers/champ_helper.rb b/app/helpers/champ_helper.rb index 16e74c4bb..fbd791e45 100644 --- a/app/helpers/champ_helper.rb +++ b/app/helpers/champ_helper.rb @@ -28,7 +28,7 @@ module ChampHelper def autosave_available?(champ) # FIXME: enable autosave on champs private? once we figured out how to batch audit events - champ.dossier&.brouillon? && !champ.repetition? + champ.dossier.brouillon? && !champ.repetition? end def editable_champ_controller(champ) @@ -39,10 +39,10 @@ module ChampHelper # This is a public champ – it can have an autosave controller. if champ.public? # This is a champ on dossier in draft state. Activate autosave. - if champ.dossier&.brouillon? + if champ.dossier.brouillon? controllers << 'autosave' # This is a champ on a dossier in en_construction state. Enable conditions checker. - elsif champ.public? && champ.dossier&.en_construction? + elsif champ.public? && champ.dossier.en_construction? controllers << 'check-conditions' end end diff --git a/app/models/champ.rb b/app/models/champ.rb index cf39e2cfd..9ba1f2165 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -89,7 +89,7 @@ class Champ < ApplicationRecord end def sections - @sections ||= dossier&.sections_for(self) + @sections ||= dossier.sections_for(self) end def mandatory_blank_and_visible?