I'm constantly getting the error when trying to paginate my products:
undefined method `total_pages' for #<Product::ActiveRecord_Relation:0x007fa19efed0c0>
I've tried lots of combinations but It still shows. I've also tried to require 'will_paginate/array' in an initializer and in application controller with no luck.
¿Can someone help with this please?
Products Controller:
def from_category
@category = Category.find(params[:cat_id])
@products = Product.where(category_id: params[:cat_id])
@filtered_products = @products.paginate(page: params[:page], per_page: 30)
respond_to do |format|
format.js
end
end
In erb view
<%= will_paginate @filtered_products %>
index.js.erb
$("#products").html("<%= escape_javascript(render("products")) %>");
you can try like this:
For
erbfile you can use like:Can you please try like this?