From 96e6adc71c7aa589ff795d619d54ea80dda2bd37 Mon Sep 17 00:00:00 2001 From: raluka Date: Wed, 16 Sep 2015 14:00:00 +0200 Subject: [PATCH] added comments to explain comments_controller --- app/controllers/admin/comments_controller.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/controllers/admin/comments_controller.rb b/app/controllers/admin/comments_controller.rb index 4fa39d32..874439df 100644 --- a/app/controllers/admin/comments_controller.rb +++ b/app/controllers/admin/comments_controller.rb @@ -3,17 +3,24 @@ module Admin load_and_authorize_resource def index + # All available comments, grouped and sorted @comments = grouped_comments(accessible_ordered_comments) + + # Grouped, sorted, available comments, posted since current_user last login @unread_comments = grouped_comments(accessible_ordered_comments.find_since_last_login(current_user)) + + # Grouped, sorted, available comments, posted by current_user @posted_comments = grouped_comments(accessible_ordered_comments.find_comments_by_user(current_user)) end private + # Returning all available comments, ordered by created_at: :desc and by event.title def accessible_ordered_comments Comment.accessible_by(current_ability).joins('INNER JOIN events ON commentable_id = events.id').order('events.title', 'comments.created_at DESC') end +# Grouping all comments by conference, and by event. It returns {:conference => {:event => [{comment_2}, {comment_1 }]}} def grouped_comments(remarks) remarks.group_by{ |comment| comment.commentable.conference }.map {|conference, comments| [conference, comments.group_by{|comment| comment.commentable}]}.to_h end