错误的未定义方法`to_key' [xxx]的数组:尝试在Active Admin table_for(Rails,Postgresql,postgres_ext gem)上使用数组数据时的数组(Error undefined method `to_key' for [xxx] :Array when trying to use array data on Active Admin table_for (Rails, Postgresql, postgres_ext gem))

3 IT屋

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?

解决方案

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'

我想使用我设法将数据放入一个数组数组中,然后将其放在Active Admin上一个仪表板上的表(table_for)中



我的应用程序是Daily Deal应用程序,旨在了解Ruby on Rails的更多信息。



感谢SO的帮助,现在我设法将所需的所有数据都存储在内部数组:
在Active Admin仪表板(Rails,Active admin 1.0,Postgresql数据库,postgres_ext gem)中的序列化属性(数组)中计数值的出现次数



我要使用的数组数据看起来像(实际上是数组的数组)
 enter图像描述在这里



但是我想要的是下图所示的东西,所以我想使用Active Admin的table_for(稍后拥有所有导出功能)上):
在此处输入图片描述



我的"我的信息中心"页面上当前的代码是



 列做

列做

数据= Deal.connection.select_rows(
%q {具有expand_deals(id,目标)为(
选择id,unnest(deal_main_goal)
来自交易)

选择目标,count(*)n来自目标的expanded_deals


依目标排序; })。每个|行|
目标= row.first
n = row.last.to_i
#....
结束

小组"最高目标"执行

table_for数据执行
#代码
结束

结束

结束
结束


即使没有在table_for数据中放入任何代码,我也已经收到错误:



 未定义的方法" to_key",用于["获取(网站或新闻通讯选择加入)"," 3"]:数组


我如何使用数组的数据将其放入标准table_for中,并将其基本列设为"目标" /"交易次数"?



我可能在AA上偶然发现一张票,上面说不可能: https://github.com/gregbell/active_admin/issues/1713



有人知道怎么做吗?


解决方案

我刚刚打开请求请求st添加此功能: https://github.com/gregbell/active_admin/pull/2812



可以让您在表中使用任意数据,例如:



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


请通过将其放入您的Gemfile中来尝试请求请求:



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


UPDATE



现在已合并到主文件中:



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

本文地址:IT屋 » 错误的未定义方法`to_key' [xxx]的数组:尝试在Active Admin table_for(Rails,Postgresql,postgres_ext gem)上使用数组数据时的数组