2011-07-19 52 views
0

什麼可能是錯的?任何幫助表示讚賞。組上奇怪的重複

@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 %> 

輸出:

16/07 
16/07 
18/07 
19/07 
+0

它可能具有在同一天創造了兩個紀錄。 – s84

+0

對不起,我不明白。你能舉個例子嗎? – rOrman

+0

'16/07'是一個日期。你可以有多個具有相同日期的entires。 – s84

回答

0

當您選擇的記錄,它是由數據庫的日期()函數,它使用什麼實際存儲在數據庫中的分組,但你選擇完整的created_at包括時間。它選擇第一個作爲價值。時區轉換將在您實際顯示時發揮作用。我敢打賭,那些16年代應該是15

嘗試:

@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 %>