app/models/ticket.rb
# Generate a discount code for this ticket.
Generate a discount code for this ticket.
Generate a discount code for this ticket .
def generate_discount_code
    if self.discount_code.nil? && self.email.present?
      s = self.ticket_kind ? (self.ticket_kind.prefix + '_') : ''
      salted_email = "#{self.email} #{Rails.application.secrets.discount_code_salt}"
      email_hash = Digest::MD5.hexdigest(salted_email)[0..6]
      email_fragment = self.email.gsub(/\W/, '')
      s << "#{email_fragment}_#{email_hash}"
      self.discount_code = s
    end
  end
def generate_discount_code if self . discount_code . nil? && self . email . present? s = self . ticket_kind ? ( self . ticket_kind . prefix + '_' ) : '' salted_email = "#{self.email} #{Rails.application.secrets.discount_code_salt}" email_hash = Digest :: MD5 . hexdigest ( salted_email ) [ 0 .. 6 ] email_fragment = self . email . gsub ( / \W / , '' ) s << "#{email_fragment}_#{email_hash}" self . discount_code = s end end
Generate a discount code for this ticket.
Generate a discount code for this ticket .
# Add a prefix to the ticket if possible # Generate a discount code based on the user's email