I have been trying to add custom attributes to jbuilder like i do in the show page to my index page for pagination with will paginate and its not displaying the custom attributes.
for example what i have in my controller action is
def index
#respond_with
@publishers = Publisher.paginate(:page => params[:page], :per_page => 30)
respond_to do |format|
format.json
end
end
and my index.json.jbuilder is
json.array!(@publishers) do |publisher|
json.extract! publisher, :id, :name, :url
json.categories do
publisher.categories.each do |category|
json.name category.name
json.id category.id
json.url url_for(category)
end
end
end
what i would like to have is
json.current_page @publishers.current_page
json.total_pages @publishers.totla_entries
json.array!(@publishers) do |publisher|
json.extract! publisher, :id, :name, :url
json.categories do
publisher.categories.each do |category|
json.name category.name
json.id category.id
json.url url_for(category)
end
end
end
so that i have have the current_page and total pages showing up in the json output of the index page.
currently what i have is
[{"id":1,"name":"facebook","url":"http://www.facebook.com","categories":{"name":"Art and Crafts","id":1,"url":"/categories/1-art-and-crafts"}}]
how can i accomplish this. i am also using willpaginate