From f67bd157a9ee4034bbd4fffd4d9824d1b6cfea7d Mon Sep 17 00:00:00 2001 From: f Date: Mon, 29 Apr 2024 14:07:34 -0300 Subject: [PATCH] feat: eliminar un valor de la lista de parametros --- app/helpers/application_helper.rb | 19 +++++++++++++++++++ app/views/sites/_header.haml | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9f7be213..7d05d1bf 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -19,6 +19,25 @@ module ApplicationHelper [root, name] end + # Devuelve los params sin el valor para una llave, detectando si el + # valor es un array. + # + # @param filtering_params [Hash] + # @param key [Symbol,String] + # @param value [Any] + def filter_params_by(filtering_params, key, value) + filtering_params.map do |k, v| + if k == key + case v + when Array then [k, v - [value]] + else nil + end + else + [ k, v ] + end + end.compact.to_h + end + def plain_field_name_for(*names) root, name = field_name_for(*names) diff --git a/app/views/sites/_header.haml b/app/views/sites/_header.haml index 4bd7a073..c4936853 100644 --- a/app/views/sites/_header.haml +++ b/app/views/sites/_header.haml @@ -15,7 +15,7 @@ %input.sr-only{ type: 'submit' } - @filter_params.each do |param, values| - [values].flatten.each do |value| - = link_to site_posts_path(@site, **@filter_params), + = link_to site_posts_path(@site, **filter_params_by(@filter_params, param, value)), class: 'btn btn-secondary btn-sm', title: t('posts.remove_filter_help', filter: value), aria: { labelledby: "help-filter-#{param}" } do