Ruby on rails 在Rails3中格式化按日期分组的输出

Ruby on rails 在Rails3中格式化按日期分组的输出,ruby-on-rails,activerecord,ruby-on-rails-3.1,Ruby On Rails,Activerecord,Ruby On Rails 3.1,我已经按照帖子中的说明按日期对一组结果进行分组并添加计数 我的视图中的输出如下所示: {Sun, 30 Oct 2011=>17, Wed, 02 Nov 2011=>19, Fri, 11 Nov 2011=>70, Sat, 12 Nov 2011=>44, Sun, 13 Nov 2011=>38, Sun, 20 Nov 2011=>4, Mon, 21 Nov 2011=>5, Sun, 27 Nov 2011=>80, Sun, 04

我已经按照帖子中的说明按日期对一组结果进行分组并添加计数

我的视图中的输出如下所示:

 {Sun, 30 Oct 2011=>17, Wed, 02 Nov 2011=>19, Fri, 11 Nov 2011=>70, Sat, 12 Nov 2011=>44, Sun, 13 Nov 2011=>38, Sun, 20 Nov 2011=>4, Mon, 21 Nov 2011=>5, Sun, 27 Nov 2011=>80, Sun, 04 Dec 2011=>16, Sat, 31 Dec 2011=>48, Mon, 02 Jan 2012=>68, Tue, 03 Jan 2012=>1, Wed, 04 Jan 2012=>3, Sun, 08 Jan 2012=>9, Mon, 09 Jan 2012=>7, Wed, 11 Jan 2012=>1, Thu, 12 Jan 2012=>1}
这是我的控制器:

@radpostauth = Radpostauth.order(:authdate).group("DATE(authdate)").count

我不知道如何在表中格式化此输出?有人能帮上忙吗?

该查询将返回一个散列,因此您只需迭代该散列并将其显示在表中

下面是一个快速迭代的示例:

$ hashish = Hash.new
$ hashish = {'Sun, 30 Oct 2011'=>17, 'Wed, 02 Nov 2011'=>19, 'Fri, 11 Nov 2011'=>70, 'Sat, 12 Nov 2011'=>44, 'Sun, 13 Nov 2011'=>38, 'Sun, 20 Nov 2011'=>4, 'Mon, 21 Nov 2011'=>5, 'Sun, 27 Nov 2011'=>80, 'Sun, 04 Dec 2011'=>16, 'Sat, 31 Dec 2011'=>48, 'Mon, 02 Jan 2012'=>68, 'Tue, 03 Jan 2012'=>1, 'Wed, 04 Jan 2012'=>3, 'Sun, 08 Jan 2012'=>9, 'Mon, 09 Jan 2012'=>7, 'Wed, 11 Jan 2012'=>1, 'Thu, 12 Jan 2012'=>1}
$ hashish.each {|k,v| puts "Key is #{k} and value is #{v}"}

> Key is Sun, 30 Oct 2011 and value is 17
> Key is Wed, 02 Nov 2011 and value is 19
> Key is Fri, 11 Nov 2011 and value is 70
> Key is Sat, 12 Nov 2011 and value is 44
> Key is Sun, 13 Nov 2011 and value is 38
> Key is Sun, 20 Nov 2011 and value is 4
> Key is Mon, 21 Nov 2011 and value is 5
> Key is Sun, 27 Nov 2011 and value is 80
> Key is Sun, 04 Dec 2011 and value is 16
> Key is Sat, 31 Dec 2011 and value is 48
> Key is Mon, 02 Jan 2012 and value is 68
> Key is Tue, 03 Jan 2012 and value is 1
> Key is Wed, 04 Jan 2012 and value is 3
> Key is Sun, 08 Jan 2012 and value is 9
> Key is Mon, 09 Jan 2012 and value is 7
> Key is Wed, 11 Jan 2012 and value is 1
> Key is Thu, 12 Jan 2012 and value is 1
下面是一个在表中显示的快速示例(我使用HAML代码,因为您没有指定ERB或HAML):


该查询将返回一个散列,因此您所需要做的就是迭代该散列并将其显示在表中

下面是一个快速迭代的示例:

$ hashish = Hash.new
$ hashish = {'Sun, 30 Oct 2011'=>17, 'Wed, 02 Nov 2011'=>19, 'Fri, 11 Nov 2011'=>70, 'Sat, 12 Nov 2011'=>44, 'Sun, 13 Nov 2011'=>38, 'Sun, 20 Nov 2011'=>4, 'Mon, 21 Nov 2011'=>5, 'Sun, 27 Nov 2011'=>80, 'Sun, 04 Dec 2011'=>16, 'Sat, 31 Dec 2011'=>48, 'Mon, 02 Jan 2012'=>68, 'Tue, 03 Jan 2012'=>1, 'Wed, 04 Jan 2012'=>3, 'Sun, 08 Jan 2012'=>9, 'Mon, 09 Jan 2012'=>7, 'Wed, 11 Jan 2012'=>1, 'Thu, 12 Jan 2012'=>1}
$ hashish.each {|k,v| puts "Key is #{k} and value is #{v}"}

> Key is Sun, 30 Oct 2011 and value is 17
> Key is Wed, 02 Nov 2011 and value is 19
> Key is Fri, 11 Nov 2011 and value is 70
> Key is Sat, 12 Nov 2011 and value is 44
> Key is Sun, 13 Nov 2011 and value is 38
> Key is Sun, 20 Nov 2011 and value is 4
> Key is Mon, 21 Nov 2011 and value is 5
> Key is Sun, 27 Nov 2011 and value is 80
> Key is Sun, 04 Dec 2011 and value is 16
> Key is Sat, 31 Dec 2011 and value is 48
> Key is Mon, 02 Jan 2012 and value is 68
> Key is Tue, 03 Jan 2012 and value is 1
> Key is Wed, 04 Jan 2012 and value is 3
> Key is Sun, 08 Jan 2012 and value is 9
> Key is Mon, 09 Jan 2012 and value is 7
> Key is Wed, 11 Jan 2012 and value is 1
> Key is Thu, 12 Jan 2012 and value is 1
下面是一个在表中显示的快速示例(我使用HAML代码,因为您没有指定ERB或HAML):

%table
  - hashish.each do |k,v|
    %tr
      %td #{k}
      %td #{v}