Ho cercato di aggiungere attributi personalizzati a jbuilder come faccio nella pagina di presentazione alla mia pagina di indice per l'impaginazione con paginazione e la mancata visualizzazione degli attributi personalizzati.Come aggiungere attributi extra alla pagina dell'indice di jbuilder
per esempio quello che ho nella mia azione di controllo è
def index
#respond_with
@publishers = Publisher.paginate(:page => params[:page], :per_page => 30)
respond_to do |format|
format.json
end
end
e il mio index.json.jbuilder è
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
quello che vorrei avere è
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
così ho la pagina corrente e le pagine totali mostrate nell'output json della pagina indice.
attualmente Quello che ho è
[{"id":1,"name":"facebook","url":"http://www.facebook.com","categories":{"name":"Art and Crafts","id":1,"url":"/categories/1-art-and-crafts"}}]
come posso ottenere questo risultato. sto anche usando willpaginate
Grazie per pubblicare la tua risposta questo mi ha aiutato Penso che due dei tuoi metodi siano sbagliati. Dovresti utilizzare 'json.total_pages @ publishers.total_pages' e' json.total_records @ publishers.total_records'. – flyingL123
'@ publishers.total_records' va bene così anche' total_entries' funzionava come al 2014 – Uchenna