Refactor helpers.

This commit is contained in:
taitus
2017-09-06 13:47:29 +02:00
parent 64774b0d2d
commit c5cb463a2e
3 changed files with 6 additions and 13 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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