From 1f33aacd0b18ba3a2f5220dc25a091885e65f1da Mon Sep 17 00:00:00 2001 From: Yuki Nishijima Date: Fri, 9 Dec 2016 04:42:43 +0000 Subject: [PATCH] Raise an exception if #total_count is called on a non-count paginable scope --- .../kaminari/activerecord/active_record_relation_methods.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kaminari-activerecord/lib/kaminari/activerecord/active_record_relation_methods.rb b/kaminari-activerecord/lib/kaminari/activerecord/active_record_relation_methods.rb index a7c6f7e..af4f173 100644 --- a/kaminari-activerecord/lib/kaminari/activerecord/active_record_relation_methods.rb +++ b/kaminari-activerecord/lib/kaminari/activerecord/active_record_relation_methods.rb @@ -78,5 +78,11 @@ module Kaminari load unless loaded? @records.empty? end + + # Force to raise an exception if #total_count is called explicitly. + def total_count + raise "This scope is marked as a non-count paginable scope and can't be used in combination " \ + "with `#paginate' or `#page_entries_info'. Use #link_to_next_page or #link_to_previous_page instead." + end end end