ActiveRecordで日付の範囲指定
ActiveSupportのコア拡張を使うとめちゃ綺麗に書けて感動した。
- 今日
from = Time.now.at_beginning_of_day to = from + 1.day items = Item.where(created_at: from...to).order(created_at: :desc)
- 今月
from = Time.now.at_beginning_of_month to = from + 1.month items = Item.where(created_at: from...to).order(created_at: :desc)