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 00bb25c..6b99a17 100644
--- a/spec/helpers/action_view_extension_spec.rb
+++ b/spec/helpers/action_view_extension_spec.rb
@@ -36,6 +36,13 @@ describe 'Kaminari::ActionViewExtension', :if => defined?(::Rails::Railtie) && d
subject { helper.paginate @users, :total_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