From a781f644ac2ac34c48a5363bdf01b5d42ecafbc8 Mon Sep 17 00:00:00 2001 From: Yuki Nishijima Date: Sat, 23 Dec 2017 15:46:54 -0500 Subject: [PATCH] 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 --- kaminari-core/lib/kaminari/helpers/paginator.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kaminari-core/lib/kaminari/helpers/paginator.rb b/kaminari-core/lib/kaminari/helpers/paginator.rb index 3157b3b..f7c4cc0 100644 --- a/kaminari-core/lib/kaminari/helpers/paginator.rb +++ b/kaminari-core/lib/kaminari/helpers/paginator.rb @@ -26,7 +26,11 @@ module Kaminari # 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