ActiveRecord is not aware of timezones?

后端 未结 2 497
伪装坚强ぢ
伪装坚强ぢ 2021-01-19 07:42

I have one question regarding to time zone

I have done the following yet, my activerecord is not still matching with my timezone when I do following query

         


        
2条回答
  •  生来不讨喜
    2021-01-19 08:12

    Did you try the query by specifying the range?

    Because you're trying to find the user_stocks that are created on some date. But notice that created_at is a datetime object and I guess your date variable might be just a date object.

    def stock_by_date(date)
      UserStock.where(created_at: date.midnight..date.end_of_day, user_id: current_user.id)
    end
    

提交回复
热议问题