2010-05-19 222 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 
相关问题