简体   繁体   English

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

[英]Error undefined method `to_key' for [xxx] :Array when trying to use array data on Active Admin table_for (Rails, Postgresql, postgres_ext gem)

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 我想使用我设法获取的数据放入一个数组数组中,以将它们放在Active Admin上一个仪表板上的表(table_for)中

My app is a Daily Deal app built to learn more Ruby on Rails. 我的应用程序是Daily Deal应用程序,旨在了解更多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) 多亏了SO方面的帮助,我现在设法在阵列中获取所需的所有数据: 在Active Admin仪表板(Rails,Active admin 1.0,Postgresql数据库,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): 但是我想要的东西看起来像下面的图片,所以我想使用Active Admin的table_for(稍后再使用所有导出功能): 在此处输入图片说明

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: 即使没有在table_for数据中放入任何代码,我也已经收到错误:

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"? 如何使用数组的数据将其放入标准table_for中,并将其基本列设为“目标” /“交易数量”?

I might have stumbled upon a ticket on AA that says it might not be possible: https://github.com/gregbell/active_admin/issues/1713 我可能偶然发现了AA上的罚单,说这不可能: 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 我刚刚打开请求请求以添加此功能: 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: 请通过将其放入您的Gemfile中来尝试拉取请求:

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

UPDATE UPDATE

This has now been merged into master: 现在,它已合并到master:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 计算Active Admin仪表板(Rails,Active admin 1.0,Postgresql数据库,postgres_ext gem)中序列化属性(数组)中值的出现 - Count occurrence of values in a serialized attribute(array) in Active Admin dashboard (Rails, Active admin 1.0, Postgresql database, postgres_ext gem) Rails 3.2模式转储使用postgres_ext gem将所有UUID列转换为text和mangles数组声明 - Rails 3.2 schema dump turns all UUID columns to text and mangles array declarations with postgres_ext gem Rails 4未定义方法“ to_key” - Rails 4 undefined method 'to_key' 在postgis适配器中使用postgres_ext不适用于数组列 - Using postgres_ext with postgis adapter not working with array columns mongomapper,rails3 edge:form_for上未定义的方法“ to_key” - mongomapper, rails3 edge: undefined method `to_key' on form_for 活动管理员表中的条件检查 - Condition checking in active admin table_for 将参数传递给Active Admin Table_for列 - Passing Parameters to Active Admin Table_for columns 如何使用simple_form解决未定义的方法`to_key'错误 - How to solve undefined method `to_key' error with simple_form 使用form_for的未定义方法“ to_key”错误 - Undefined method 'to_key' error using form_for 渲染表单部分-未定义的方法“ to_key” - Rendering form partials - undefined method `to_key'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM