Remove the need to call #presence to show a fall-back HTML

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: https://github.com/kaminari/kaminari/pull/785
This commit is contained in:
Yuki Nishijima 2017-12-23 15:46:54 -05:00
parent 4ada38c911
commit a781f644ac
1 changed files with 5 additions and 1 deletions

View File

@ -26,7 +26,11 @@ module Kaminari
# render given block as a view template # render given block as a view template
def render(&block) def render(&block)
instance_eval(&block) if @options[:total_pages] > 1 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 end
# enumerate each page providing PageProxy object as the block parameter # enumerate each page providing PageProxy object as the block parameter