5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-23 02:56:22 +00:00

feat: eliminar un valor de la lista de parametros

This commit is contained in:
f 2024-04-29 14:07:34 -03:00
parent b867747291
commit f67bd157a9
No known key found for this signature in database
2 changed files with 20 additions and 1 deletions

View file

@ -19,6 +19,25 @@ module ApplicationHelper
[root, name] [root, name]
end 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) def plain_field_name_for(*names)
root, name = field_name_for(*names) root, name = field_name_for(*names)

View file

@ -15,7 +15,7 @@
%input.sr-only{ type: 'submit' } %input.sr-only{ type: 'submit' }
- @filter_params.each do |param, values| - @filter_params.each do |param, values|
- [values].flatten.each do |value| - [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', class: 'btn btn-secondary btn-sm',
title: t('posts.remove_filter_help', filter: value), title: t('posts.remove_filter_help', filter: value),
aria: { labelledby: "help-filter-#{param}" } do aria: { labelledby: "help-filter-#{param}" } do