Forum: Ruby on Rails Display custom links above top level arrays using Jbuilder

Posted by Mohnish J. (mohnish_j)
on 2013-03-14 05:45
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.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.