Extract ProcedurePath#find_by_path

This commit is contained in:
Paul Chavard 2018-09-07 17:28:27 +01:00
parent 9a216ae705
commit de908ef4be
2 changed files with 8 additions and 4 deletions

View file

@ -205,10 +205,7 @@ class Admin::ProceduresController < AdminController
def path_list
json_path_list = ProcedurePath
.joins(:procedure)
.where(procedures: { archived_at: nil })
.where("path LIKE ?", "%#{params[:request]}%")
.order(:id)
.find_with_path(params[:request])
.pluck(:path, :administrateur_id)
.map do |path, administrateur_id|
{

View file

@ -6,6 +6,13 @@ class ProcedurePath < ApplicationRecord
belongs_to :procedure
belongs_to :administrateur
def self.find_with_path(path)
joins(:procedure)
.where.not(procedures: { aasm_state: :archivee })
.where("path LIKE ?", "%#{path}%")
.order(:id)
end
def hide!
destroy!
end