I am trying to cache requests that come in for Products. I am using the Kaminari gem for pagination but for some reason I cannot see all the products on my view page. It seems to only take the top 25 and list those.
def index
cache_key = Product::CACHE_KEY_PREFIX + params.map{|k,v| "[#{k}-#{v}]"}.join("-")
@products = Rails.cache.fetch(cache_key, expires_in: 30.minutes) do
search_params = params.permit(:product_type,:format).to_h.symbolize_keys
if search_params[:product_type]
products = Product.by_product_type(params[:product_type])
elsif params[:filters].present?
filters = params[:filters].try(:symbolize_keys)
products = Product.where(filters)
else
products = Product.all
end
byebug #at this point products count is 43
products = products.page(params[:page])
byebug #count is now 25
@products = Kaminari.paginate_array(products.to_a).page(params[:page])
@products #count is 25
end
respond_to do |format|
format.html
format.json
end
end