1
votes

I'd like to have use the data I manage to get inside an array of array to put them inside a table(table_for) on one of my Dashboards on Active Admin

My app is a Daily Deal app built to learn more Ruby on Rails.

Thanks to help on SO, I now manage to get all the data i need inside an Array: Count occurrence of values in a serialized attribute(array) in Active Admin dashboard (Rails, Active admin 1.0, Postgresql database, postgres_ext gem)

The array's data I want to use looks like (it's actually an array of array) enter image description here

But what i'd like is something looking like the image below, so i want to use Active Admin's table_for (to have all the export features later on): enter image description here

My current code on my Dashboard page is

columns do 

  column do

    data = Deal.connection.select_rows(
        %q{ with expanded_deals(id, goal) as (
        select id, unnest(deal_main_goal)
        from deals)

        select goal, count(*) n
        from expanded_deals
        group by goal
        order by goal; }).each do |row|
        goal = row.first
        n    = row.last.to_i
        #....
      end

    panel "Top Goals" do

      table_for data do
          #code
      end

    end  

  end
end  

Even without putting any code inside table_for data, I already get the error:

undefined method `to_key' for ["Acquisition (website or newsletter opt-ins)", "3"]:Array

How can I use the array's data to put them inside a standard table_for with my basic columns "goal"/"number of deals"?

I might have stumbled upon a ticket on AA that says it might not be possible: https://github.com/gregbell/active_admin/issues/1713

Would anybody know how to do that?

1

1 Answers

2
votes

I just opened a pull request to add this functionality: https://github.com/gregbell/active_admin/pull/2812

Which lets you use arbitrary data in a table, like this:

table_for foo: 1, bar: 2 do
  column :foo
  column :bar
end

Please give the pull request a try by putting this in your Gemfile:

gem 'activeadmin', github: 'seanlinsley/active_admin',
                   branch: 'feature/1713-support_arbitrary_objects_for_tables'

UPDATE

This has now been merged into master:

gem 'activeadmin', github: 'gregbell/active_admin'