开发者

Rails created_at find condition

开发者 https://www.devze.com 2022-12-29 02:11 出处:网络
I\'m attempting to sum daily purchase amounts for a given user. @dates is an array of 31 dates. I need the find condition to compare a date from the array to the created_at date of the purchases. What

I'm attempting to sum daily purchase amounts for a given user. @dates is an array of 31 dates. I need the find condition to compare a date from the array to the created_at date of the purchases. What I'm doing below compares the exact DateTime for the create_at column. I need it to look at the day itself, not the DateTime.

How can I write this so created_at is in between the date from the array?

<% @dates.each do |date| %>
  <td><%=开发者_JAVA百科 current_user.purchases.sum(:amount, :conditions => ["created_at = ?", date]) %></td>
<% end %>


:conditions => {:created_at => start_date..finish_date}


You need to find the starting and ending dates in that array and then you will be able to the entries where created_at is in between using this:

:conditions => ["created_at >= ? AND created_at <= ?", start_date, finish_date]
0

精彩评论

暂无评论...
验证码 换一张
取 消