错误的未定义方法`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)

查看:112
本文介绍了错误的未定义方法`to_key' [xxx]的数组:尝试在Active Admin table_for(Rails,Postgresql,postgres_ext gem)上使用数组数据时的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



感谢SO的帮助,现在我设法将所需的所有数据都存储在内部数组:



有人知道怎么做吗?

解决方案

我刚刚打开请求请求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'


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)

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):

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'

这篇关于错误的未定义方法`to_key' [xxx]的数组:尝试在Active Admin table_for(Rails,Postgresql,postgres_ext gem)上使用数组数据时的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆