From b762b82e74775a57ecce33e731b609ad940675bc Mon Sep 17 00:00:00 2001 From: raluka Date: Tue, 8 Sep 2015 12:15:22 +0200 Subject: [PATCH] rewrite CommentsController#index to have everything in one call --- app/controllers/admin/comments_controller.rb | 3 +-- app/views/admin/comments/_all_comments.html.haml | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/comments_controller.rb b/app/controllers/admin/comments_controller.rb index ebcc9f92..088d07f5 100644 --- a/app/controllers/admin/comments_controller.rb +++ b/app/controllers/admin/comments_controller.rb @@ -3,8 +3,7 @@ module Admin load_and_authorize_resource def index - @comments = Comment.accessible_by(current_ability).order(created_at: :desc).group_by { |comment| comment.commentable.conference } - @another_comments = Hash[@comments.map{|conference, comments| [conference, comments.group_by {|comment| comment.commentable}]}] + @comments = Comment.accessible_by(current_ability).order(created_at: :desc).group_by { |comment| comment.commentable.conference }.map {|conference, comments| [conference, comments.group_by {|comment| comment.commentable}]}.to_h end end end diff --git a/app/views/admin/comments/_all_comments.html.haml b/app/views/admin/comments/_all_comments.html.haml index a08b6eb9..25f6b474 100644 --- a/app/views/admin/comments/_all_comments.html.haml +++ b/app/views/admin/comments/_all_comments.html.haml @@ -1,6 +1,6 @@ .panel.well %ul - - @another_comments.each do |conference, events| + - @comments.each do |conference, events| %li= conference.title - events.each do |event, comments| %li= event.title