2014-11-16 40 views
0
<% current_user.events.find(:all, conditions: ("start" > DateTime.now)).limit(5).each do |e| %> 
    <%= e.start %> 
<% end %> 

我收到此錯誤信息:地圖時間戳的DateTime

invalid date 

這不起作用,因爲格式不正確。 我可以使用e.start.to_date然後我可以將e.event與TimeDate.now比較,但我不知道如何將值映射到DateTime。

如果我不喜歡這樣寫道:

<% current_user.events.map! { |e| e.start.to_date }.limit(5).each do |e| %> 
<%= e.start %> 
<% end %> 

它是一個數組,因此,良好的限制,其中,選擇活動記錄方法就不管用了。

基本上我想將所有的起始值映射到日期,然後我想比較它們,只顯示今天的事件或未來的事件,但不是過去的事件。

你會如何解決這個問題?

回答

1

你可以嘗試:

current_user.events.where("start > ?", Time.now.to_date) 
+0

感謝就像一個魅力。 –