Rails ActiveRecord Query Date Range

后端 未结 2 1967
Happy的楠姐
Happy的楠姐 2021-02-05 00:58

I\'m trying to use the following line in my controller to capture all tasks due less than a week from the current date:

@due_this_week = current_user.tasks.where         


        
相关标签:
2条回答
  • 2021-02-05 01:53

    Turns out my controller somehow wasn't set up correctly and was no longer saving the current_user's ID when creating new assignments, which is why they weren't being found. I figured this out using the rails console and running a find on the last few assignments submitted. The user_id was set to nil. Thanks for the assist @mu is too short.

    0 讨论(0)
  • 2021-02-05 01:58

    Should be:

    @due_this_week = current_user.tasks.where(due_date: 1.week.ago..Date.today)
    
    0 讨论(0)
提交回复
热议问题