Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adding option to display for one page of results #342

Closed
wants to merge 2 commits into from

3 participants

@steveklebanoff

Adds a configuration variable that lets you display the pagination if there is only one page of results.

@ivasilov

Awesome gem @mislav!

Can you merge this small change? I really need it.

@mislav
Owner

Nope. See my comment on #76 (comment)

@mislav mislav closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
10 lib/will_paginate/view_helpers.rb
@@ -58,6 +58,8 @@ class << self
# * <tt>:page_links</tt> -- when false, only previous/next links are rendered (default: true)
# * <tt>:container</tt> -- toggles rendering of the DIV container for pagination links, set to
# false only when you are rendering your own pagination markup (default: true)
+ # * <tt>:display_if_single_page</tt> -- determines if output should be rendered
+ # if there is only one page of results. default: false
#
# All options not recognized by will_paginate will become HTML attributes on the container
# element for pagination links (the DIV). For example:
@@ -70,7 +72,13 @@ class << self
#
def will_paginate(collection, options = {})
# early exit if there is nothing to render
- return nil unless collection.total_pages > 1
+ if collection.total_pages <= 1
+ unless (options[:display_if_single_page] == true &&
+ collection.total_pages == 1 &&
+ collection.count > 0)
+ return nil
+ end
+ end
options = WillPaginate::ViewHelpers.pagination_options.merge(options)
View
4 spec/view_helpers/action_view_spec.rb
@@ -60,6 +60,10 @@ def render(locals)
paginate(:per_page => 30).should be_empty
end
+ it "should render something when there is only 1 page if display_if_single_page option sent in" do
+ paginate({:per_page => 30}, :display_if_single_page => true ).should_not be_empty
+ end
+
it "should paginate with options" do
paginate({ :page => 2 }, :class => 'will_paginate', :previous_label => 'Prev', :next_label => 'Next') do
assert_select 'a[href]', 4 do |elements|
Something went wrong with that request. Please try again.