diff --git a/app/components/avo/paginator_component.rb b/app/components/avo/paginator_component.rb index cfac81f33d..ddcaabf554 100644 --- a/app/components/avo/paginator_component.rb +++ b/app/components/avo/paginator_component.rb @@ -3,6 +3,7 @@ class Avo::PaginatorComponent < Avo::BaseComponent prop :resource prop :parent_record + prop :parent_resource prop :pagy prop :turbo_frame do |frame| frame.present? ? CGI.escapeHTML(frame) : :_top @@ -12,7 +13,14 @@ class Avo::PaginatorComponent < Avo::BaseComponent def change_items_per_page_url(option) if @parent_record.present? - helpers.related_resources_path(@parent_record, @parent_record, per_page: option, keep_query_params: true, page: 1) + helpers.related_resources_path( + @parent_record, + @parent_record, + parent_resource: @parent_resource, + per_page: option, + keep_query_params: true, + page: 1 + ) else helpers.resources_path(resource: @resource, per_page: option, keep_query_params: true, page: 1) end diff --git a/app/components/avo/views/resource_index_component.html.erb b/app/components/avo/views/resource_index_component.html.erb index 25e56dc0f1..9cbe4aa5dc 100644 --- a/app/components/avo/views/resource_index_component.html.erb +++ b/app/components/avo/views/resource_index_component.html.erb @@ -79,7 +79,7 @@ <% if view_type.to_sym == :table || view_type.to_sym == :map %> <% if @records.present? %>
- <%= render Avo::PaginatorComponent.new pagy: @pagy, turbo_frame: @turbo_frame, index_params: @index_params, resource: @resource, parent_record: @parent_record, discreet_pagination: field&.discreet_pagination %> + <%= render Avo::PaginatorComponent.new pagy: @pagy, turbo_frame: @turbo_frame, index_params: @index_params, resource: @resource, parent_record: @parent_record, parent_resource: @parent_resource, discreet_pagination: field&.discreet_pagination %>
<% end %> <% end %> @@ -88,7 +88,7 @@ <%= render Avo::Index::ResourceGridComponent.new(resources: @resources, resource: @resource, reflection: @reflection, parent_record: @parent_record, parent_resource: @parent_resource, actions: @actions) %>
- <%= render Avo::PaginatorComponent.new pagy: @pagy, turbo_frame: @turbo_frame, index_params: @index_params, resource: @resource, parent_record: @parent_record, discreet_pagination: field&.discreet_pagination %> + <%= render Avo::PaginatorComponent.new pagy: @pagy, turbo_frame: @turbo_frame, index_params: @index_params, resource: @resource, parent_record: @parent_record, parent_resource: @parent_resource, discreet_pagination: field&.discreet_pagination %>
<% end %> <% end %> diff --git a/app/helpers/avo/url_helpers.rb b/app/helpers/avo/url_helpers.rb index 07460dff10..97e47b30f1 100644 --- a/app/helpers/avo/url_helpers.rb +++ b/app/helpers/avo/url_helpers.rb @@ -61,6 +61,7 @@ def related_resources_path( parent_record, record, keep_query_params: false, + parent_resource: nil, **args ) return if record.nil? @@ -75,7 +76,9 @@ def related_resources_path( rescue end - avo.resources_associations_index_path(parent_record.model_name.route_key, record.to_param, **existing_params, **args) + route_key = parent_resource&.route_key || parent_record.model_name.route_key + + avo.resources_associations_index_path(route_key, record.to_param, **existing_params, **args) end def resource_view_path(**args)