ActiveAdmin AJAX autorefreshing parcial
Frecuentes
Visto 3,189 equipos
1
I just have a simple index page which shows all the items of an ActiveRecord. What I'd like to have is that the table containing the items gets automatically refreshed every X seconds (i.e. loaded from the DB and rendered). I already redefined the index action as a partial rendering
[app/admin/item.rb]
ActiveAdmin.register Item do
index do
render :partial => "items_list"
end
end
And then I have
[app/views/admin/items/_items_list.html.erb]
(I don't mind using ERB or ARB to write the partial) The list table is rendered correctly when I first load the page.
I'm not sure which Javascript I should include in the page to refresh the list every X seconds. More specifically, which URL should be called by the Javascript command? Do I need to define any custom action in the controller?
Gracias por cualquier consejo.
Thomas
1 Respuestas
3
I finally managed it.
[app/admin/item.rb]
ActiveAdmin.register Item do
...
index do
# do nothing; table will be filled with a partial via Javascript
end
collection_action :items_list do
@items = Item.all
render :partial => "items_list"
end
end
[app/views/admin/_items_list.html.arb]
table_for items do
column "attr_1"
column "attr_2"
column "attr_3"
end
[app/assets/javascripts/items.js]
$(document).ready( function() {
setInterval(function(){
$('#index_table_items').load('items/items_list');},1000);
})
finally append to app/assets/javascripts/active_admin.js
el siguiente
//= require inbox_files
This way I get the list table updated every second. Also the CSS doesn't get distorted.
Respondido el 04 de junio de 14 a las 16:06
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas ajax activeadmin reload renderpartial or haz tu propia pregunta.