Module: AgreementsHelper

Defined in:
app/helpers/agreements_helper.rb

Overview

View helper: agreements.

Form-setup helpers for Agreement records and their nested
AgreementParticipant / ContactPoint associations.

See Also:

Instance Method Summary collapse

Instance Method Details

#setup_agreement(agreement) ⇒ Agreement

Builds a default agreement participant on the agreement when none exist,
so the form always renders at least one nested participant field.

Parameters:

  • agreement (Agreement)

    the agreement being set up for the form

Returns:

  • (Agreement)

    the same agreement, with a participant built if it had none



14
15
16
17
18
# File 'app/helpers/agreements_helper.rb', line 14

def setup_agreement(agreement)
  agreement.tap do |a|
    a.agreement_participants.build if sc.agreement_participants.blank?
  end
end

#setup_agreement_participant(agreement_participant) ⇒ AgreementParticipant

Builds a default party (Contact) and EMAIL/PHONE contact points on the
participant, so the form renders the nested fields it needs.

Parameters:

Returns:



25
26
27
28
29
30
31
32
33
# File 'app/helpers/agreements_helper.rb', line 25

def setup_agreement_participant(agreement_participant)
  agreement_participant.tap do |ap|
    ap.party ||= Contact.new
    if ap.party.contact_points.empty?
      ap.party.contact_points.build(category: ContactPoint::EMAIL)
      ap.party.contact_points.build(category: ContactPoint::PHONE)
    end
  end
end