Display custom links above top level arrays using Jbuilder

I have a custom JSON response in which I display a collection of 15
posts along with related data like comments etc., as part of an API
call. I am displaying the entire collection using Jbuilder .

json.array!(@posts) do |post|


end
I want to display pagination links above the response of the 15 posts,
in order to get the next set of posts with the appropriate next set of
next page and prev page pagination links. In my abc.json.jbuilder file
if I try doing it as per the below code, I don’t get links to the next
and prev page as part of my json response.

json.pagination_links do
json.set!(:next_page_link,"#{@next_page_link}")
json.set!(:prev_page_link,"#{@prev_page_link}")
end

json.array!(@posts) do |post|


end
The only response, that I get is the array which has a collection of
posts. Which looks like below:-

[
-{post1}
-{post2}
-…
]
I guess there is something that I might be missing. Can anybody please
suggest me any work arounds?

Thanks.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs