Answer the question
In order to leave comments, you need to log in
How to display the total number of items?
I'm using Rails 5.1.6 and the kaminari gem and api-pagination for pagination. And at the moment I have 10 records on one JSON page, but how can I add the total number of records on each json page? If I'm not mistaken, then you need to add ":collection => @posts" to the render, but this does not work for me.
class PostsController < ApplicationController
def post
posts = paginate Post.all, per_page: 10
render json: JSON.pretty_generate(posts.as_json)
end
def index
post
end
end
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question