Fay007
Fay007

Reputation: 2917

How do i render data from db into dashboard page generated by ActiveAdmin?

Is it possible to render data from other db files or with query to show in the default dashboard page generated by ActiveAdmin in Ruby on Rails. I am very new to the engine and would like an explanation on how to do it?

So far when i try to call the db by it's name, table_for cannot render any data, which i suppose is the correct response:

# columns do
    #   panel "Test" do
    #     table_for Test do
    #       column "Title", :name
    #       column "Id", :id
    #     end
    #   end
    # end

The file where i am trying to load data:

ActiveAdmin.register_page "Dashboard" do

Upvotes: 1

Views: 482

Answers (2)

anjosebar
anjosebar

Reputation: 41

Yes, it is possible. You should be able to render a table based on an ActiveRecord query result. Instead of using the class name table_for Test do, you should use the ActiveRecord query table_for Test.all do or your query. For example:

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

You can display any information using the Arbre Components o rendering an ERB file partial with render partial: 'important_information'

Upvotes: 1

Josh Brody
Josh Brody

Reputation: 5363

Sure. You can use panel, table_for Order.all, etc. Here's an example:

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

Upvotes: 0

Related Questions