Skip to content

Commit

Permalink
Remove the need to call #presence to show a fall-back HTML
Browse files Browse the repository at this point in the history
Right now, the #paginate method doesn't show anything when there's only one
page. While this is expected, some times there's a case where showing a fall
back message is appropriate. In order to do so, a subsequent #presence call is
needed because the #paginate method always returns a string. This commit adds a
 #presence call to the #render method, so it'll be a little cleaner to show a
fall-back message.

  related: kaminari#785
  • Loading branch information
yuki24 committed Dec 23, 2017
1 parent 4ada38c commit a781f64
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion kaminari-core/lib/kaminari/helpers/paginator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ def initialize(template, window: nil, outer_window: Kaminari.config.outer_window
# render given block as a view template
def render(&block)
instance_eval(&block) if @options[:total_pages] > 1
@output_buffer

# This allows for showing fall-back HTML when there's only one page:
#
# <%= paginate(@search_results) || "Showing all search results" %>
@output_buffer.presence
end

# enumerate each page providing PageProxy object as the block parameter
Expand Down

0 comments on commit a781f64

Please sign in to comment.