From 25560a27fc84e5c775d08fdf6ed54b535b39746b Mon Sep 17 00:00:00 2001 From: taitus Date: Wed, 6 Sep 2017 14:07:44 +0200 Subject: [PATCH] Refactor Community model. --- app/models/community.rb | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/app/models/community.rb b/app/models/community.rb index 369c355ff..3fa1cebaa 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -4,8 +4,8 @@ class Community < ActiveRecord::Base has_many :topics def participants - users_participants = users_who_commented_by + - users_who_topics_author_by + + users_participants = users_who_commented + + users_who_topics_author + author_from_community users_participants.uniq end @@ -16,24 +16,19 @@ class Community < ActiveRecord::Base private - def users_who_commented_by + def users_who_commented topics_ids = topics.pluck(:id) query = "comments.commentable_id IN (?)and comments.commentable_type = 'Topic'" User.by_comments(query, topics_ids) end - def users_who_topics_author_by + def users_who_topics_author author_ids = topics.pluck(:author_id) User.by_authors(author_ids) end def author_from_community - if from_proposal? - User.where(id: proposal.author_id) - else - investment = Budget::Investment.where(community_id: id).first - User.where(id: investment.author_id) - end + from_proposal? ? User.where(id: proposal.author_id) : User.where(id: investment.author_id) end end