Class: ContactForm

Inherits:
ApplicationRecord show all
Includes:
MailForm::Delivery
Defined in:
app/models/contact_form.rb

Overview

== Schema Information

Table name: contact_forms
Database name: primary

id :integer not null, primary key
object :jsonb
type :string(50) not null
created_at :datetime
updated_at :datetime
creator_id :integer
visit_id :integer

Indexes

index_contact_forms_on_visit_id (visit_id) WHERE (visit_id IS NOT NULL) USING hash

Foreign Keys

fk_rails_... (visit_id => visits.id) ON DELETE => nullify

Constant Summary collapse

EMAIL_REGEXP =
RFC822::EMAIL

Belongs to collapse

Has many collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Method Details

#email_sender_nameObject



40
41
42
43
44
45
46
47
48
49
# File 'app/models/contact_form.rb', line 40

def email_sender_name
  names = []
  names << try(:company_name)
  names << try(:customer_name_or_id)
  names << try(:first_name)
  names << try(:last_name)
  names << try(:name)
  names.compact!
  names.join(' ')
end

#fromObject



66
67
68
69
70
71
72
# File 'app/models/contact_form.rb', line 66

def from
  if email_sender_name.present?
    %("#{email_sender_name}" <#{email_address}>)
  else
    email_address
  end
end

#headersObject



75
76
77
78
79
80
81
# File 'app/models/contact_form.rb', line 75

def headers
  {
    subject: "[#{self.class.name}] (#{id}) #{email_sender_name}",
    to: to,
    from: from
  }
end

#toObject



62
63
64
# File 'app/models/contact_form.rb', line 62

def to
  'webmaster@warmlyyours.com'
end

#type_cast_order_dateObject



52
53
54
55
56
57
58
59
60
# File 'app/models/contact_form.rb', line 52

def type_cast_order_date
  return unless respond_to?(:order_date)
  return if order_date.blank?
  return if order_date.is_a?(Date)
  
  # Cast string to date, preserve original value if parsing fails
  parsed = Date.parse(order_date.to_s) rescue nil
  self.order_date = parsed if parsed
end

#uploadsActiveRecord::Relation<Upload>

Returns:

  • (ActiveRecord::Relation<Upload>)

See Also:



30
# File 'app/models/contact_form.rb', line 30

has_many :uploads, as: :resource, dependent: :destroy

#visitVisit

Returns:

See Also:



28
# File 'app/models/contact_form.rb', line 28

belongs_to :visit, optional: true