在rake任务中使用hirb

时间:2012-08-11 01:03:53

标签: ruby ruby-on-rails-3 rake hirb

我想通过hirb在rake任务中得到很好的打印效果。但我无法弄清楚如何设置hirb来打印ActiveRecord结果。

task :t2 => :environment do
  require 'hirb'
  Hirb.enable
  result = Task.select('project_id, COUNT(*) AS counter').group('project_id').order('counter DESC')
  puts Hirb::Helpers::Table.render(result)
  Hirb.disable
end

我遇到错误“表必须是哈希数组或数组数组”

1 个答案:

答案 0 :(得分:3)

puts Hirb::Helpers::AutoTable.render(active_record_object)