我如何将数据库中的数据呈现到 ActiveAdmin 生成的仪表板页面中?
How do i render data from db into dashboard page generated by ActiveAdmin?
是否可以呈现来自其他数据库文件的数据或使用查询显示在 Rails 上 Ruby 中由 ActiveAdmin
生成的默认仪表板页面中。我对引擎很陌生,想了解如何操作?
到目前为止,当我尝试通过名称调用数据库时,table_for 无法呈现任何数据,我认为这是正确的响应:
# columns do
# panel "Test" do
# table_for Test do
# column "Title", :name
# column "Id", :id
# end
# end
# end
我尝试加载数据的文件:
ActiveAdmin.register_page "Dashboard" do
当然可以。您可以使用 panel
、table_for Order.all
等。这是一个示例:
ActiveAdmin.register_page "Dashboard" do
content do
columns do
column span: 2 do
panel "Processing Orders" do
h5 do
Order.processing.count
end
end
end
column span: 2 do
panel "Completed Orders" do
h5 do
Order.completed.count
end
end
end
end
end
end
是的,这是可能的。您应该能够根据 ActiveRecord 查询结果呈现 table。您应该使用 ActiveRecord 查询 table_for Test.all do
或您的查询,而不是使用 class 名称 table_for Test do
。例如:
panel "Pending Dealers" do
table_for Dealer.pending.last(5) do
column :id
column :name do |dealer|
link_to dealer.name, admin_dealer_path(dealer)
end
column :email
column :created_at
end
end
您可以使用 Arbre Components 显示任何信息 o 使用 render partial: 'important_information'
渲染部分 ERB 文件
是否可以呈现来自其他数据库文件的数据或使用查询显示在 Rails 上 Ruby 中由 ActiveAdmin
生成的默认仪表板页面中。我对引擎很陌生,想了解如何操作?
到目前为止,当我尝试通过名称调用数据库时,table_for 无法呈现任何数据,我认为这是正确的响应:
# columns do
# panel "Test" do
# table_for Test do
# column "Title", :name
# column "Id", :id
# end
# end
# end
我尝试加载数据的文件:
ActiveAdmin.register_page "Dashboard" do
当然可以。您可以使用 panel
、table_for Order.all
等。这是一个示例:
ActiveAdmin.register_page "Dashboard" do
content do
columns do
column span: 2 do
panel "Processing Orders" do
h5 do
Order.processing.count
end
end
end
column span: 2 do
panel "Completed Orders" do
h5 do
Order.completed.count
end
end
end
end
end
end
是的,这是可能的。您应该能够根据 ActiveRecord 查询结果呈现 table。您应该使用 ActiveRecord 查询 table_for Test.all do
或您的查询,而不是使用 class 名称 table_for Test do
。例如:
panel "Pending Dealers" do
table_for Dealer.pending.last(5) do
column :id
column :name do |dealer|
link_to dealer.name, admin_dealer_path(dealer)
end
column :email
column :created_at
end
end
您可以使用 Arbre Components 显示任何信息 o 使用 render partial: 'important_information'