Add auto champs objects at a dossier (same as PJ)

Add dynamic of Champs on the description page
Rename model 'Champs' to 'Champ'
This commit is contained in:
Xavier J 2015-11-03 15:27:49 +01:00
parent 56eccf55df
commit 27dbd3a878
14 changed files with 103 additions and 81 deletions

View file

@ -19,10 +19,12 @@ class Dossier < ActiveRecord::Base
delegate :siren, to: :entreprise
delegate :siret, to: :etablissement
delegate :types_de_piece_justificative, to: :procedure
delegate :types_de_champs, to: :procedure
before_create :build_default_cerfa
after_save :build_default_pieces_justificatives, if: Proc.new { procedure_id_changed? }
after_save :build_default_champs, if: Proc.new { procedure_id_changed? }
validates :nom_projet, presence: true, allow_blank: false, allow_nil: true
validates :description, presence: true, allow_blank: false, allow_nil: true
@ -33,11 +35,18 @@ class Dossier < ActiveRecord::Base
end
def build_default_pieces_justificatives
procedure.types_de_piece_justificative.each do |type_de_piece_justificative|
PieceJustificative.create(type_de_piece_justificative_id: type_de_piece_justificative.id, dossier_id: id)
end
end
def build_default_champs
procedure.types_de_champs.each do |type_de_champs|
Champ.create(type_de_champs_id: type_de_champs.id, dossier_id: id)
end
end
def sous_domaine
if Rails.env.production?
'tps'