Skip to content

Commit 2207fac

Browse files
committed
Previous page uses per_page value
1 parent 3b1e1fd commit 2207fac

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

app/helpers/pagination_helper.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,23 @@ def prev_url(query_params)
6464

6565
# First page gets a disabled link in a span
6666
if query_params[:page].blank? || query_params[:page].to_i == 1
67-
"<span role='link' aria-disabled='true' tabindex='-1'>#{prev_page_label}</span>".html_safe
67+
"<span role='link' aria-disabled='true' tabindex='-1'>#{prev_page_label(query_params[:page].to_i || 1)}</span>".html_safe
6868
else
69-
link_to results_path(params_copy), 'aria-label': prev_page_label,
69+
link_to results_path(params_copy), 'aria-label': prev_page_label(query_params[:page].to_i || 1),
7070
data: { turbo_frame: 'search-results', turbo_action: 'advance' },
7171
rel: 'nofollow' do
72-
prev_page_label.html_safe
72+
prev_page_label(query_params[:page].to_i || 1).html_safe
7373
end
7474
end
7575
end
7676

77-
def prev_page_label
78-
'Previous 20 results'
77+
def prev_page_label(current_page = 1)
78+
label = if current_page == 1
79+
0
80+
else
81+
@pagination[:per_page]
82+
end
83+
84+
"Previous #{label} results"
7985
end
8086
end

test/helpers/pagination_helper_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class PaginationHelperTest < ActionView::TestCase
9090
@pagination = { prev: nil, per_page: 20, hits: 100, end: 20 }
9191
query_params = { q: 'popcorn', page: 1 }
9292
assert_equal(
93-
"<span role='link' aria-disabled='true' tabindex='-1'>Previous 20 results</span>", prev_url(query_params)
93+
"<span role='link' aria-disabled='true' tabindex='-1'>Previous 0 results</span>", prev_url(query_params)
9494
)
9595
end
9696
end

0 commit comments

Comments
 (0)