Ruby on rails 群上的奇怪重复

Ruby on rails 群上的奇怪重复,ruby-on-rails,Ruby On Rails,有什么不对劲?感谢您的帮助 @entries = Entry.where(:created_at => 3.day.ago.beginning_of_day..Time.now.end_of_day).group("date(created_at)").select("created_at, count(id) as tcount") <% @entries.each_with_index do |entry, index| %> <%= entry.created_a

有什么不对劲?感谢您的帮助

@entries = Entry.where(:created_at => 3.day.ago.beginning_of_day..Time.now.end_of_day).group("date(created_at)").select("created_at, count(id) as tcount")

<% @entries.each_with_index do |entry, index| %>
<%= entry.created_at.strftime("%d/%m") %>
<% end %>

当您选择记录时,它是通过数据库的date()函数进行分组的,该函数使用数据库中实际存储的内容,但您选择的是完整的创建时间,包括时间。它选择第一个作为值。时区转换将在您实际显示时发挥作用。我打赌16个应该是15个

尝试:

@entries=Entry.where(:created_at=>3.day.ago.开始日期..时间.现在.结束日期).组(“date(created_at)”)。选择(“date(created_at)作为日期,count(id)作为tcount”)

可以在同一天创建两条记录。对不起,我不明白。你能给我举个例子吗?
16/07
是一个日期。你可以有多个同一日期的实体。我在创建时对条目进行了分组,为什么会看到重复的组名?为什么会投反对票?这实际上是一个好的、棘手的问题!
16/07
16/07
18/07
19/07
@entries = Entry.where(:created_at => 3.day.ago.beginning_of_day..Time.now.end_of_day).group("date(created_at)").select("date(created_at) as date, count(id) as tcount")

<% @entries.each_with_index do |entry, index| %>
<%= entry.date.strftime("%d/%m") %>
<% end %>