Class: Rooftop::Rails::Extras::ContactForm

Inherits:
MailForm::Base
  • Object
show all
Defined in:
app/models/rooftop/rails/extras/contact_form.rb

Constant Summary collapse

DEFAULT_FIELDS =
{
  name: :text_field,
  email: :text_field,
  message: :text_area
}

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.fieldsObject

Returns the value of attribute fields.



6
7
8
# File 'app/models/rooftop/rails/extras/contact_form.rb', line 6

def fields
  @fields
end

.fromObject

Returns the value of attribute from.



6
7
8
# File 'app/models/rooftop/rails/extras/contact_form.rb', line 6

def from
  @from
end

.headersObject

Returns the value of attribute headers.



6
7
8
# File 'app/models/rooftop/rails/extras/contact_form.rb', line 6

def headers
  @headers
end

.subjectObject

Returns the value of attribute subject.



6
7
8
# File 'app/models/rooftop/rails/extras/contact_form.rb', line 6

def subject
  @subject
end

.toObject

Returns the value of attribute to.



6
7
8
# File 'app/models/rooftop/rails/extras/contact_form.rb', line 6

def to
  @to
end

Class Method Details

.setup!Object



15
16
17
18
19
20
21
22
23
24
# File 'app/models/rooftop/rails/extras/contact_form.rb', line 15

def self.setup!
  (self.fields || DEFAULT_FIELDS).keys.each do |field|
    self.send(:attribute,field, {validate: true})
  end

  self.subject ||= "Contact form message"
  self.to ||= "change.me@#{self.to_s.underscore}"
  self.from ||= "change.me@#{self.to_s.underscore}"
  self.headers ||= {}
end

Instance Method Details

#fieldsObject



36
37
38
# File 'app/models/rooftop/rails/extras/contact_form.rb', line 36

def fields
  self.class.fields
end

#headersObject

Declare the e-mail headers. It accepts anything the mail method in ActionMailer accepts.



28
29
30
31
32
33
34
# File 'app/models/rooftop/rails/extras/contact_form.rb', line 28

def headers
  {
    subject: self.class.subject,
    to: self.class.to,
    from: %("Contact form" <#{self.class.from}>)
  }.merge(self.class.headers)
end