【问题标题】:Error undefined method `to_key' for [xxx] :Array when trying to use array data on Active Admin table_for (Rails, Postgresql, postgres_ext gem)[xxx] 的错误未定义方法“to_key”:尝试在 Active Admin table_for(Rails、Postgresql、postgres_ext gem)上使用数组数据时的数组
【发布时间】:2013-12-22 14:45:37
【问题描述】:

我想使用我设法进入数组数组的数据,将它们放在我的一个 Dashboards on Active Admin 上的表(table_for)中

我的应用是一款 Daily Deal 应用,旨在了解更多 Ruby on Rails。

感谢 SO 的帮助,我现在设法在一个数组中获取我需要的所有数据: Count occurrence of values in a serialized attribute(array) in Active Admin dashboard (Rails, Active admin 1.0, Postgresql database, postgres_ext gem)

我要使用的数组的数据看起来像(它实际上是一个数组数组)

但我想要的是看起来像下图的东西,所以我想使用 Active Admin 的 table_for(稍后拥有所有导出功能):

我的仪表板页面上的当前代码是

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  

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

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

如何使用数组的数据将它们放入标准 table_for 中,基本列为“目标”/“交易数量”?

我可能偶然发现了一张关于 AA 的票说这可能是不可能的:https://github.com/gregbell/active_admin/issues/1713

有人知道怎么做吗?

【问题讨论】:

    标签: ruby-on-rails arrays ruby-on-rails-3 postgresql activeadmin


    【解决方案1】:

    我刚刚打开了一个拉取请求来添加这个功能: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',
                       branch: 'feature/1713-support_arbitrary_objects_for_tables'
    

    更新

    现在已经合并到master中:

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

    【讨论】:

    • 顺便说一句,我刚刚更新了我的答案,因为该拉取请求已合并到 master 中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    • 1970-01-01
    相关资源
    最近更新 更多