Class: Contact::Form

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Conversion, ActiveModel::Validations
Defined in:
app/models/contact/form.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Form

So we can batch update to instatiate the contact form, i.e. Contact.new(params)



15
16
17
18
19
# File 'app/models/contact/form.rb', line 15

def initialize(attributes = {})
  attributes.each do |name, value|
    send("#{name}=", value)
  end
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



10
11
12
# File 'app/models/contact/form.rb', line 10

def body
  @body
end

#sender_emailObject

Returns the value of attribute sender_email.



10
11
12
# File 'app/models/contact/form.rb', line 10

def sender_email
  @sender_email
end

#sender_nameObject

Returns the value of attribute sender_name.



10
11
12
# File 'app/models/contact/form.rb', line 10

def sender_name
  @sender_name
end

#subjectObject

Returns the value of attribute subject.



10
11
12
# File 'app/models/contact/form.rb', line 10

def subject
  @subject
end

Instance Method Details

#fromObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/contact/form.rb', line 21

def from
  case
  when self.sender_name.present? && self.sender_email.present?
    "#{self.sender_name} <#{self.sender_email}>"
  when self.sender_name.present?
    self.sender_name
  when self.sender_email.present?
    self.sender_email
  else
    "Annonymous User <#{CONTACT['default_recipients']}>"
  end
end

#persisted?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/contact/form.rb', line 34

def persisted?
  false
end