在activeadmin中自定义csv格式会禁用csv下载链接

时间:2014-09-10 16:06:21

标签: ruby-on-rails activeadmin

我有一个带有温和定制的ActiveAdmin注册用户表的rails应用程序。 app / admin / users.rb看起来像这样:

ActiveAdmin.register User do
  actions :index, :show

  preserve_default_filters!
  filter :referrer, collection: User.all.map{ |user| [user.email, user.id] }
  filter :referrals, collection: User.all.map{ |user| [user.email, user.id] }

  index do 
    column :id
    column("Name")              { |user| user.first_name + " " + user.last_name }
    column :email
    column("Referrer", :referrer, :sortable => :referrer_id)
    column :referral_code
    column("Created at", :created_at, :sortable => :created_at)
    column("Referral count")    { |user| user.referrals.count }
    actions
  end
end

这可以按预期工作。但我还想自定义csv文件下载的布局。所以我在最后一个结尾之前添加了这个块:

  csv do 
    column :id
    column("Name")        { |user| user.first_name + " " + user.last_name }
    column :email
    column("Referrer", :referrer)
    column :referral_code
    column("Created at", :created_at)
    column("Referral count")  { |user| user.referrals.count }
  end

添加后,单击CSV链接在浏览器中不执行任何操作。我正在本地与工头一起运行应用程序,点击链接后显示以下错误:

08:58:12 web.1    | E, [2014-09-10T08:58:12.818820 #4610] ERROR -- : app error: no implicit conversion of Symbol into Hash (TypeError)
08:58:12 web.1    | E, [2014-09-10T08:58:12.818937 #4610] ERROR -- : /Users/maxnorton/.bundler/ruby/2.0.0/active_admin-bf9dabe6a568/lib/active_admin/csv_builder.rb:41:in `merge'
08:58:12 web.1    | E, [2014-09-10T08:58:12.818999 #4610] ERROR -- : /Users/maxnorton/.bundler/ruby/2.0.0/active_admin-bf9dabe6a568/lib/active_admin/csv_builder.rb:41:in `column'
08:58:12 web.1    | E, [2014-09-10T08:58:12.819059 #4610] ERROR -- : /Users/maxnorton/Documents/dev/prelaunchr/app/admin/users.rb:23:in `block (2 levels) in <top (required)>'
08:58:12 web.1    | E, [2014-09-10T08:58:12.819116 #4610] ERROR -- : /Users/maxnorton/.bundler/ruby/2.0.0/active_admin-bf9dabe6a568/lib/active_admin/csv_builder.rb:59:in `instance_exec'
08:58:12 web.1    | E, [2014-09-10T08:58:12.819176 #4610] ERROR -- : /Users/maxnorton/.bundler/ruby/2.0.0/active_admin-bf9dabe6a568/lib/active_admin/csv_builder.rb:59:in `exec_columns'
08:58:12 web.1    | E, [2014-09-10T08:58:12.819233 #4610] ERROR -- : /Users/maxnorton/.bundler/ruby/2.0.0/active_admin-bf9dabe6a568/lib/active_admin/csv_builder.rb:46:in `build'
08:58:12 web.1    | E, [2014-09-10T08:58:12.819289 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/actionpack-4.1.4/lib/action_dispatch/http/response.rb:95:in `each'
08:58:12 web.1    | E, [2014-09-10T08:58:12.819363 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/actionpack-4.1.4/lib/action_dispatch/http/response.rb:95:in `each'
08:58:12 web.1    | E, [2014-09-10T08:58:12.819421 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/actionpack-4.1.4/lib/action_dispatch/http/response.rb:95:in `each'
08:58:12 web.1    | E, [2014-09-10T08:58:12.819477 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/actionpack-4.1.4/lib/action_dispatch/http/response.rb:50:in `each'
08:58:12 web.1    | E, [2014-09-10T08:58:12.819534 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/body_proxy.rb:31:in `each'
08:58:12 web.1    | E, [2014-09-10T08:58:12.819591 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/body_proxy.rb:31:in `each'
08:58:12 web.1    | E, [2014-09-10T08:58:12.819654 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/body_proxy.rb:31:in `each'
08:58:12 web.1    | E, [2014-09-10T08:58:12.819712 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/body_proxy.rb:31:in `each'
08:58:12 web.1    | E, [2014-09-10T08:58:12.819767 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/body_proxy.rb:31:in `each'
08:58:12 web.1    | E, [2014-09-10T08:58:12.819822 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/body_proxy.rb:31:in `each'
08:58:12 web.1    | E, [2014-09-10T08:58:12.819876 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/body_proxy.rb:31:in `each'
08:58:12 web.1    | E, [2014-09-10T08:58:12.819931 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/lint.rb:647:in `each'
08:58:12 web.1    | E, [2014-09-10T08:58:12.819987 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/body_proxy.rb:31:in `each'
08:58:12 web.1    | E, [2014-09-10T08:58:12.820042 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/chunked.rb:23:in `each'
08:58:12 web.1    | E, [2014-09-10T08:58:12.820100 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_response.rb:60:in `http_response_write'
08:58:12 web.1    | E, [2014-09-10T08:58:12.820193 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:586:in `process_client'
08:58:12 web.1    | E, [2014-09-10T08:58:12.820252 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:670:in `worker_loop'
08:58:12 web.1    | E, [2014-09-10T08:58:12.820307 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:525:in `spawn_missing_workers'
08:58:12 web.1    | E, [2014-09-10T08:58:12.820362 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:140:in `start'
08:58:12 web.1    | E, [2014-09-10T08:58:12.820417 #4610] ERROR -- : /Library/Ruby/Gems/2.0.0/gems/unicorn-4.8.3/bin/unicorn:126:in `<top (required)>'
08:58:12 web.1    | E, [2014-09-10T08:58:12.820471 #4610] ERROR -- : /usr/bin/unicorn:23:in `load'
08:58:12 web.1    | E, [2014-09-10T08:58:12.820525 #4610] ERROR -- : /usr/bin/unicorn:23:in `<main>'

似乎第一个错误行可能是关键,但我不确定它指的是哪个符号。我做错了什么?

1 个答案:

答案 0 :(得分:1)

试试这个:

...
column("Referrer")  { |user| user.referrer }
column :referral_code
column("Created at")  { |user| user.created_at }
...