我们正在使用Active Admin和Rails构建应用程序。它具有一系列具有相同数据结构的模型。
现在,我们想要一个视图,将这些模型中的所有数据一起显示在一个表中。
之所以分成许多模型,是因为它们全部来自不同的来源。
因此,作为管理员,我想一起查看所有数据。
该数据是只读的,因此无需写入。
使用下面的代码,我可以将所有数据与一个自定义页面一起呈现,但是这没有利用表呈现中内置的ActiveAdmin,因此毫无意义。请参见下面的屏幕截图和使用的代码。
ActiveAdmin.register_page "Top Sellers" do
content do
table_for @items = Dingoat.all + Dingobe.all do
column "Product Name", :ProductName
column "Start Date", :StartDate
column "End Date", :EndDate
end
end
end
您的方法是使用ActiveAdmin表组件。唯一缺少的是将其包装在面板中:
ActiveAdmin.register_page "Top Sellers" do
content do
panel "Sellers" do
table_for(Dingoat.all + Dingobe.all) do
column "Product Name", :ProductName
column "Start Date", :StartDate
column "End Date", :EndDate
end
end
end
end
或者,您可以设置其样式以使其看起来像索引页:
ActiveAdmin.register_page "Top Sellers" do
content do
# Note the addition of index_table class.
table_for(Dingoat.all + Dingobe.all, class: 'index_table') do
column "Product Name", :ProductName
column "Start Date", :StartDate
column "End Date", :EndDate
end
end
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句