Last active
August 29, 2015 14:16
-
-
Save mikedijkstra/04a7c1acb6b1e434e55d to your computer and use it in GitHub Desktop.
Rails: Group by day showing empty days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
notifications = Notifications.where('notifications.created_at BETWEEN ? AND ?', start_date, end_date) | |
notifications_by_date = notifications.group_by { |notification| notification.created_at.to_date } | |
@notifications_by_day = (start_date.to_date..end_date.to_date).map do |date| | |
{ | |
day: date, | |
notifications: notifications_by_date[date] || [], | |
} | |
end | |
@notifications_by_day.reverse! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment