diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index 533987cf9..f22d44d38 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -150,9 +150,7 @@ module Instructeurs end def add_filter - if params[:value].present? - procedure_presentation.add_filter(statut, params[:field], params[:value]) - end + procedure_presentation.add_filter(statut, params[:field], params[:value]) redirect_back(fallback_location: instructeur_procedure_url(procedure)) end diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 18aa50bf0..d0eb61ec6 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -197,16 +197,15 @@ class ProcedurePresentation < ApplicationRecord def add_filter(statut, field, value) if value.present? - updated_filters = self.filters table, column = field.split('/') label = find_field(table, column)['label'] case table when 'type_de_champ', 'type_de_champ_private' - type_de_champ = TypeDeChamp.find_by(id: column) - value = type_de_champ.dynamic_type.human_to_filter(value) + value = find_type_de_champ(column).dynamic_type.human_to_filter(value) end + updated_filters = filters.dup updated_filters[statut] << { 'label' => label, 'table' => table, @@ -214,7 +213,7 @@ class ProcedurePresentation < ApplicationRecord 'value' => value } - update(filters: updated_filters) + update!(filters: updated_filters) end end