Skip to content

Commit fa0ee24

Browse files
committed
Merge pull request activeadmin#751 from DMajrekar/active_admin
--- Setting a custom @per_page through a before_filter fetches the correct number of records but the text in the pagination is incorrect. Using collection.size rather than active_admin_application.default_per_page yields the correct text.
2 parents 666046d + 750f4ca commit fa0ee24

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

features/index/pagination.feature

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
11
Feature: Index Pagination
22

33
Background:
4+
Scenario: Viewing index when one page of resources exist
45
Given an index configuration of:
56
"""
67
ActiveAdmin.register Post
78
"""
8-
Scenario: Viewing index when one page of resources exist
99
Given 20 posts exist
1010
When I am on the index page for posts
1111
Then I should see "Displaying all 20 Posts"
1212
And I should not see pagination
1313

1414
Scenario: Viewing index when multiple pages of resources exist
15+
Given an index configuration of:
16+
"""
17+
ActiveAdmin.register Post
18+
"""
1519
Given 31 posts exist
1620
When I am on the index page for posts
1721
Then I should see pagination with 2 pages
22+
23+
Scenario: Viewing index with a custom per page set
24+
Given an index configuration of:
25+
"""
26+
ActiveAdmin.register Post do
27+
before_filter :only => :index do |controller|
28+
@per_page = 10
29+
end
30+
end
31+
"""
32+
Given 11 posts exist
33+
When I am on the index page for posts
34+
Then I should see pagination with 2 pages
35+
And I should see "Displaying Posts 1 - 10 of 11 in total"

lib/active_admin/views/components/paginated_collection.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def build(collection, options = {})
4242
unless collection.respond_to?(:num_pages)
4343
raise(StandardError, "Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.")
4444
end
45-
45+
4646
div(page_entries_info(options).html_safe, :class => "pagination_information")
4747
@contents = div(:class => "paginated_collection_contents")
4848
build_pagination_with_formats
@@ -70,7 +70,7 @@ def build_pagination_with_formats
7070
def build_pagination
7171
options = request.query_parameters.except(:commit, :format)
7272
options[:param_name] = @param_name if @param_name
73-
73+
7474
text_node paginate(collection, options.symbolize_keys)
7575
end
7676

@@ -107,9 +107,9 @@ def page_entries_info(options = {})
107107
else; I18n.t('active_admin.pagination.one_page', :model => entries_name, :n => collection.size)
108108
end
109109
else
110-
offset = collection.current_page * active_admin_application.default_per_page
110+
offset = collection.current_page * collection.size
111111
total = collection.total_count
112-
I18n.t('active_admin.pagination.multiple', :model => entries_name, :from => (offset - active_admin_application.default_per_page + 1), :to => offset > total ? total : offset, :total => total)
112+
I18n.t('active_admin.pagination.multiple', :model => entries_name, :from => (offset - collection.size + 1), :to => offset > total ? total : offset, :total => total)
113113
end
114114
end
115115

0 commit comments

Comments
 (0)