From c5cb463a2ed0fdff47317990d0590086a9221bc5 Mon Sep 17 00:00:00 2001 From: taitus Date: Wed, 6 Sep 2017 13:47:29 +0200 Subject: [PATCH] Refactor helpers. --- app/helpers/comments_helper.rb | 4 ++-- app/helpers/communities_helper.rb | 13 +++---------- app/models/community.rb | 2 +- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 1ab6c9826..bdd2ccb68 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -42,7 +42,7 @@ module CommentsHelper def commentable_path(comment) commentable = comment.commentable - + case comment.commentable_type when "Budget::Investment" budget_investment_path(commentable.budget_id, commentable) @@ -51,7 +51,7 @@ module CommentsHelper when "Legislation::Annotation" legislation_process_draft_version_annotation_path(commentable.draft_version.process, commentable.draft_version, commentable) when "Topic" - community_topic_path(comment.commentable.community, comment.commentable) + community_topic_path(commentable.community, commentable) else commentable end diff --git a/app/helpers/communities_helper.rb b/app/helpers/communities_helper.rb index 1d50c5388..bb770a948 100644 --- a/app/helpers/communities_helper.rb +++ b/app/helpers/communities_helper.rb @@ -1,12 +1,7 @@ module CommunitiesHelper def community_title(community) - if community.from_proposal? - community.proposal.title - else - investment = Budget::Investment.where(community_id: community.id).first - investment.title - end + community.from_proposal? ? community.proposal.title : community.investment.title end def community_text(community) @@ -21,8 +16,7 @@ module CommunitiesHelper if community.from_proposal? community.proposal.author_id == participant.id else - investment = Budget::Investment.where(community_id: community.id).first - investment.author_id == participant.id + community.investment.author_id == participant.id end end @@ -30,8 +24,7 @@ module CommunitiesHelper if community.from_proposal? proposal_path(community.proposal) else - investment = Budget::Investment.where(community_id: community.id).first - budget_investment_path(investment.budget_id, investment) + budget_investment_path(community.investment.budget_id, community.investment) end end diff --git a/app/models/community.rb b/app/models/community.rb index 710982200..369c355ff 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -1,6 +1,6 @@ class Community < ActiveRecord::Base has_one :proposal - has_one :investment + has_one :investment, class_name: Budget::Investment has_many :topics def participants