move validation in model for dossier
This commit is contained in:
parent
bab43c5cd3
commit
e5e2fef8ae
5 changed files with 82 additions and 28 deletions
|
@ -37,9 +37,6 @@ class DescriptionController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
if check_missing_attributes(params)
|
||||
redirect_to url_for(controller: :description, action: :error)
|
||||
else
|
||||
if params[:back_url] == 'recapitulatif'
|
||||
commentaire = Commentaire.create
|
||||
commentaire.email = 'Modification détails'
|
||||
|
@ -49,7 +46,7 @@ class DescriptionController < ApplicationController
|
|||
end
|
||||
|
||||
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: @dossier.id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -57,9 +54,4 @@ class DescriptionController < ApplicationController
|
|||
def create_params
|
||||
params.permit(:nom_projet, :description, :montant_projet, :montant_aide_demande, :date_previsionnelle, :lien_plus_infos, :mail_contact)
|
||||
end
|
||||
|
||||
# TODO dans un validateur, dans le model
|
||||
def check_missing_attributes(params)
|
||||
params[:nom_projet].strip == '' || params[:description].strip == '' || params[:montant_projet].strip == '' || params[:montant_aide_demande].strip == '' || params[:date_previsionnelle].strip == '' || params[:mail_contact].strip == ''
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,6 +15,12 @@ class Dossier < ActiveRecord::Base
|
|||
after_save :build_default_pieces_jointes, if: Proc.new { formulaire_id_changed? }
|
||||
|
||||
validates :mail_contact, format: { with: /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/ }, unless: 'mail_contact.nil?'
|
||||
validates :nom_projet, presence: true, allow_blank: false, allow_nil: true
|
||||
validates :description, presence: true, allow_blank: false, allow_nil: true
|
||||
validates :montant_projet, presence: true, allow_blank: false, allow_nil: true
|
||||
validates :montant_aide_demande, presence: true, allow_blank: false, allow_nil: true
|
||||
validates :date_previsionnelle, presence: true, allow_blank: false, unless: Proc.new { description.nil? }
|
||||
|
||||
|
||||
def retrieve_piece_jointe_by_type(type)
|
||||
pieces_jointes.where(type_piece_jointe_id: type).last
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue