Scoping date attribute for this week?

后端 未结 1 997
[愿得一人]
[愿得一人] 2021-01-07 11:52

I am trying to scope all of my Products for this week, so it should show all the products leading up to whichever day of the week.

class Product < ActiveR         


        
相关标签:
1条回答
  • 2021-01-07 12:48

    at_beginning_of_week has been removed in Rails 3. You should use beginning_of_week but, be careful, it's an instance method. So you have to do something like:

    Date.today.beginning_of_week
    

    Furthermore, you can use a range and make your query very nice to read:

    where(:purchase_date => Date.today.beginning_of_week..Date.today.end_of_week)
    
    0 讨论(0)
提交回复
热议问题