I am trying to paginate using kaminari on my rails app. On the first page i want to show 11 products and in all other pages i want to show 12 products. I followed the instructions on this post but get the following error:
undefined local variable or method `params' for #<Product::ActiveRecord_AssociationRelation:0x007fcef461e908>
See below for the show method being used:
@page = (params[:page]).to_i
if @page == 1
@products = Store.find(params[:id]).products.order(sort_column + ' ' + sort_direction).limit(11)
else
@products = Store.find(params[:id]).products.order(sort_column + ' ' + sort_direction).limit(12).offset(@page*12-13)
end
@products.instance_eval <<-EVAL
def current_page
#{@page}
end
def total_pages
((Store.find(params[:id]).products.all.count+1)/12.0).ceil
end
EVAL
The error is generated in the store#show in the following line of code:
<%= paginate @products %>