2010-05-19 55 views
-2

我有經歷了一週的每一天的方法:如何查找在特定日期發生的所有日期時間?

def dates_week(d, delim) 
     "<tr>" + (d.beginning_of_week...(d.beginning_of_week+5)).map do |day| 
     "<#{delim}> #{yield(day)} </#{delim}>" 
    end.join + "</tr>" 

    end 

對於一週的每一天,我插上,作爲一個ARG到一個方法(或者一個named_scope,還沒有想出哪些),然後輸出.count:所有在該日期具有:date_sent的電子郵件。但是,:date_sent是一個日期時間戳,所以我不能使用==,因爲我有下面。

def sent_emails_by_date(date) 
    ContactEmail.find(:all, :conditions => "date_sent = '#{date}'" 
    ").count 
    end 

例如,在查看這是我使用:

<table class='reports'> 
    <%= dates_week(Date.today, "th") {|d| d.strftime("%A")} %> 
    <%= dates_week(Date.today, "td") {|d| sent_emails_by_date(d)}%> 
</table> 

如何找到那年秋天的一天,從它通過循環的方法通過的日期的郵件星期如上所示?

+0

你是什麼'date'參數的格式? – 2010-05-19 12:56:49

+0

\t <%= dates_week(Date.today,「th」){| d | d.strftime(「%A」)}%> \t <%= dates_week(Date.today,「td」){| d | sent_emails_by_date(d)}%>
Angela 2010-05-19 23:17:57

回答

0

嘗試

def send_emails_by_date(date) 
    ContactEmail.find(:all, :conditions => { :date_sent => (date.at_beginning_of_day)...(date.end_of_day)).count 
end 
相關問題