Comparing params is fragile, use id for saved filters
This commit is contained in:
@@ -10,6 +10,10 @@ module FilterScoped
|
||||
|
||||
def set_filter
|
||||
@expand_all = params[:expand_all]
|
||||
@filter = Current.user.filters.from_params params.reverse_merge(**DEFAULT_PARAMS).permit(*Filter::PERMITTED_PARAMS)
|
||||
if params[:filter_id].present?
|
||||
@filter = Current.user.filters.find(params[:filter_id])
|
||||
else
|
||||
@filter = Current.user.filters.from_params params.reverse_merge(**DEFAULT_PARAMS).permit(*Filter::PERMITTED_PARAMS)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ class FiltersController < ApplicationController
|
||||
|
||||
def create
|
||||
@filter = Current.user.filters.remember filter_params
|
||||
redirect_to cards_path(@filter.as_params)
|
||||
redirect_to cards_path(filter_id: @filter.id)
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<strong class="popup__group-title">Saved filters</strong>
|
||||
<% @filters.each do |filter| %>
|
||||
<div class="popup__group flex align-center full-width gap-half overflow-ellipsis" data-filter-target="item" data-navigable-list-target="item">
|
||||
<%= link_to cards_path(**filter.as_params), class: "btn popup__new popup__item" do %>
|
||||
<%= link_to cards_path(filter_id: filter.id), class: "btn popup__new popup__item" do %>
|
||||
<%= icon_tag "bookmark" %>
|
||||
<div class="flex flex-column txt-tight-lines min-width txt-small">
|
||||
<span class="overflow-ellipsis"><%= filter_selected_collections_sentence(filter).html_safe %></span>
|
||||
|
||||
@@ -28,9 +28,8 @@
|
||||
<% end %>
|
||||
|
||||
<% if any_filters?(filter) %>
|
||||
<% existing_filter = Current.user.filters.find_by_params(filter.as_params) %>
|
||||
<% if existing_filter&.persisted? %>
|
||||
<%= button_to filter_path(existing_filter), method: :delete, class: "btn txt-x-small btn--reversed", form_class: "inline" do %>
|
||||
<% if filter.persisted? %>
|
||||
<%= button_to filter_path(filter), method: :delete, class: "btn txt-x-small btn--reversed", form_class: "inline" do %>
|
||||
<%= icon_tag "bookmark" %>
|
||||
<span class="for-screen-reader">Remove saved filter</span>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user