Module: EffectiveActsAsEmailFormHelper

Defined in:
app/helpers/effective_acts_as_email_form_helper.rb

Instance Method Summary collapse

Instance Method Details

#email_form_fields(form, action = nil, skip: true, to: nil, variables: nil, partial: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/helpers/effective_acts_as_email_form_helper.rb', line 5

def email_form_fields(form, action = nil, skip: true, to: nil, variables: nil, partial: nil)
  raise('expected a form') unless form.respond_to?(:object)

  resource = form.object
  raise('expected an acts_as_email_form resource') unless resource.class.respond_to?(:acts_as_email_form?)

  # Load the template.
  email_template = if action.present? && resource.email_form_effective_email_templates?
    Effective::EmailTemplate.where(template_name: action).first!
  end

  # These defaults are only used when there is no email_template
  email_defaults = form.object.email_form_defaults(action) unless email_template.present?

  locals = {
    form: form,
    email_to: to,
    email_skip: skip,
    email_action: (action || true),
    email_defaults: email_defaults,
    email_template: email_template,
    email_variables: variables
  }

  render(partial: (partial || 'effective/acts_as_email_form/fields'), locals: locals)
end