Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AnkurVyas-BTC/37564bebb3c8bc66a3e312e6cb177711 to your computer and use it in GitHub Desktop.
Save AnkurVyas-BTC/37564bebb3c8bc66a3e312e6cb177711 to your computer and use it in GitHub Desktop.
Index method of the message controller.
class MessagesController < ApplicationController
def index
@message = Message.all
#Retrives all messages and divides into two groups todays messages and other messages
@grouped_messages = @message.group_by{ |t| t.created_at.to_date == DateTime.now.to_date }
if @grouped_messages[false].present?
#Create month wise groups of messages
@month_wise_sorted_alerts = @grouped_messages[false].group_by{ |t| t.created_at.month}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment