Skip to content

Instantly share code, notes, and snippets.

@ACPK
Created December 3, 2013 18:42
Show Gist options
  • Save ACPK/a01d9cc609ad58689b1b to your computer and use it in GitHub Desktop.
Save ACPK/a01d9cc609ad58689b1b to your computer and use it in GitHub Desktop.
app/models/ticket_reply.rb
class TicketReply < ActiveRecord::Base
attr_accessible :ticket_id,:email, :from_email, :from_name, :headers, :html, :sender, :subject, :tags, :text, :to, :notification_status, :message
belongs_to :ticket
before_save :create_message
before_save :create_from_to
def create_message
h = self.html.split('>').first
if h.scan("
").empty?
f = h
else
f = h.split('
').first[15..-1]
end
self.message = f
end
def create_from_to
if self.from_email == self.ticket.contact.email
fm = self.ticket.business.callred_email
fn = self.ticket.business.name
else
fm = self.ticket.user.callred_email
fn = self.ticket.user.name
end
if self.to == self.ticket.business.callred_email
tm = self.ticket.business.email
tn = self.ticket.business.name
else
tm = self.ticket.user.email
tn = self.ticket.user.name
end
self.from_mail = fm
self.from_name = fn
self.to_mail = tm
self.to_name = tn
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment