From 11b49de733d37bf8690bdb7d87238ad930cc4a4f Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 29 Dec 2023 13:37:17 +0100 Subject: [PATCH 1/2] Fix resource filter select We need to use the permitted search filter params in order to have the correct filter selected. --- app/views/alchemy/admin/resources/_filter.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/alchemy/admin/resources/_filter.html.erb b/app/views/alchemy/admin/resources/_filter.html.erb index 520df6d12f..3f03ddacc2 100644 --- a/app/views/alchemy/admin/resources/_filter.html.erb +++ b/app/views/alchemy/admin/resources/_filter.html.erb @@ -3,7 +3,7 @@ <%= select_tag( filter.name, options_for_select( - filter.options_for_select, params[:filter].try(:[], filter.name) + filter.options_for_select, search_filter_params.dig(:filter, filter.name) ), include_blank: Alchemy.t(:all, scope: ['resources', resource_name, 'filters']), data: { remote: !!request.xhr? }, From d006e029ee11cf525262ee71eeb44caf2a9404ad Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 29 Dec 2023 13:41:33 +0100 Subject: [PATCH 2/2] Fix per page select for Rails 7 Rails 7 params do not inherit from `Hash` anymore. In order to keep existing filters we need to check for `ActionController::Parameters`. --- app/views/alchemy/admin/resources/_per_page_select.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/alchemy/admin/resources/_per_page_select.html.erb b/app/views/alchemy/admin/resources/_per_page_select.html.erb index 9786499391..c6911f6e05 100644 --- a/app/views/alchemy/admin/resources/_per_page_select.html.erb +++ b/app/views/alchemy/admin/resources/_per_page_select.html.erb @@ -1,6 +1,6 @@ <%= form_tag url_for, method: :get, class: 'per-page-select-form' do |f| %> <% search_filter_params.reject { |k, _| k == 'page' || k == 'per_page' }.each do |key, value| %> - <% if value.is_a? Hash %> + <% if value.is_a? ActionController::Parameters %> <% value.each do |k, v| %> <%= hidden_field_tag "#{key}[#{k}]", v, id: nil %> <% end %>