Skip to content

Commit 23abfe2

Browse files
committed
enh(): paginate_tag
1 parent 84616a2 commit 23abfe2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/liquid-rails/tags/paginate_tag.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ def render(context)
3737
@context = context
3838

3939
context.stack do
40-
collection = context[@collection_name]
41-
raise ::Liquid::ArgumentError.new("Cannot paginate array '#{@collection_name}'. Not found.") if collection.nil?
40+
collection = @context[@collection_name].presence || @context.environments[0][@collection_name]
41+
raise ::Liquid::ArgumentError.new("Cannot paginate collection '#{@collection_name}'. Not found.") if collection.nil?
4242

4343
if collection.is_a? Array
4444
paginated_collection = Kaminari.paginate_array(collection.to_a).page(current_page).per(@page_size)
45-
elsif collection.respond_to?(:page) && collection.respond_to?(:per)
45+
elsif collection.respond_to?(:page)
4646
paginated_collection = collection.page(current_page).per(@page_size)
4747
end
4848

0 commit comments

Comments
 (0)