mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 02:46:21 +00:00
feat: eliminar un valor de la lista de parametros
This commit is contained in:
parent
b867747291
commit
f67bd157a9
2 changed files with 20 additions and 1 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue