Class: Decidim::Proposals::Proposal

Inherits:
ApplicationRecord show all
Includes:
Authorable, HasCategory, HasFeature, HasScope, Resourceable
Defined in:
app/models/decidim/proposals/proposal.rb

Overview

The data store for a Proposal in the Decidim::Proposals component.

Instance Method Summary collapse

Instance Method Details

#accepted?Boolean

Public: Checks if the organization has accepted a proposal.

Returns Boolean.

Returns:

  • (Boolean)


46
47
48
# File 'app/models/decidim/proposals/proposal.rb', line 46

def accepted?
  state == "accepted"
end

#answered?Boolean

Public: Checks if the organization has given an answer for the proposal.

Returns Boolean.

Returns:

  • (Boolean)


39
40
41
# File 'app/models/decidim/proposals/proposal.rb', line 39

def answered?
  answered_at.present?
end

#author_avatar_urlObject



25
26
27
# File 'app/models/decidim/proposals/proposal.rb', line 25

def author_avatar_url
  author&.avatar&.url || ActionController::Base.helpers.asset_path("decidim/default-avatar.svg")
end

#author_nameObject



21
22
23
# File 'app/models/decidim/proposals/proposal.rb', line 21

def author_name
  user_group&.name || author&.name || I18n.t("decidim.proposals.models.proposal.fields.official_proposal")
end

#rejected?Boolean

Public: Checks if the organization has rejected a proposal.

Returns Boolean.

Returns:

  • (Boolean)


53
54
55
# File 'app/models/decidim/proposals/proposal.rb', line 53

def rejected?
  state == "rejected"
end

#voted_by?(user) ⇒ Boolean

Public: Check if the user has voted the proposal.

Returns Boolean.

Returns:

  • (Boolean)


32
33
34
# File 'app/models/decidim/proposals/proposal.rb', line 32

def voted_by?(user)
  votes.any? { |vote| vote.author == user }
end