From 711ece7f0ffc9f85bd02e19244439636414ef770 Mon Sep 17 00:00:00 2001 From: Igor Kasyanchuk Date: Thu, 9 Jul 2015 00:00:10 +0300 Subject: [PATCH] hide Next & Last buttons if page is out of range --- app/views/kaminari/_paginator.html.erb | 6 ++++-- spec/helpers/action_view_extension_spec.rb | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/views/kaminari/_paginator.html.erb b/app/views/kaminari/_paginator.html.erb index 4fb445f..26689bd 100644 --- a/app/views/kaminari/_paginator.html.erb +++ b/app/views/kaminari/_paginator.html.erb @@ -17,7 +17,9 @@ <%= gap_tag %> <% end -%> <% end -%> - <%= next_page_tag unless current_page.last? %> - <%= last_page_tag unless current_page.last? %> + <% unless current_page.out_of_range? %> + <%= next_page_tag unless current_page.last? %> + <%= last_page_tag unless current_page.last? %> + <% end %> <% end -%> diff --git a/spec/helpers/action_view_extension_spec.rb b/spec/helpers/action_view_extension_spec.rb index 6a64dfc..e1d7c87 100644 --- a/spec/helpers/action_view_extension_spec.rb +++ b/spec/helpers/action_view_extension_spec.rb @@ -33,6 +33,13 @@ describe 'Kaminari::ActionViewExtension', :if => defined?(Rails) do subject { helper.paginate @users, :num_pages => 3, :params => {:controller => 'users', :action => 'index'} } it { should match(/Last/) } end + + context "page: 20 (out of range)" do + before { @users = User.page(20) } + subject { helper.paginate @users, :params => {:controller => 'users', :action => 'index'} } + it { should_not match(/Last/) } + it { should_not match(/Next/) } + end end describe '#link_to_previous_page' do