Add ProcedurePath#valid?
This commit is contained in:
parent
f2f3c54147
commit
e6485603c4
2 changed files with 6 additions and 11 deletions
|
@ -94,17 +94,7 @@ class Admin::ProceduresController < AdminController
|
|||
def publish
|
||||
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||
|
||||
new_procedure_path = ProcedurePath.new(
|
||||
{
|
||||
path: params[:procedure_path],
|
||||
procedure: procedure,
|
||||
administrateur: procedure.administrateur
|
||||
}
|
||||
)
|
||||
|
||||
if new_procedure_path.validate
|
||||
new_procedure_path.delete
|
||||
else
|
||||
if !ProcedurePath.valid?(procedure, params[:procedure_path])
|
||||
flash.alert = 'Lien de la démarche invalide'
|
||||
return redirect_to admin_procedures_path
|
||||
end
|
||||
|
|
|
@ -6,6 +6,11 @@ class ProcedurePath < ApplicationRecord
|
|||
belongs_to :procedure
|
||||
belongs_to :administrateur
|
||||
|
||||
def self.valid?(procedure, path)
|
||||
create_with(procedure: procedure, administrateur: procedure.administrateur)
|
||||
.find_or_initialize_by(path: path).validate
|
||||
end
|
||||
|
||||
def self.find_with_path(path)
|
||||
joins(:procedure)
|
||||
.where.not(procedures: { aasm_state: :archivee })
|
||||
|
|
Loading…
Reference in a new issue