Sha256: 07018eabe0a29c46d4e6e988b2c21f77d1c1dc895fb5404e84928cc3c7ed0e87

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

module C80OrderForm
  class MessageOrderMailer < ActionMailer::Base

    default from: Proc.new { SiteProp.first.mail_from },
            to: Proc.new { SiteProp.first.mail_to }

    def send_mess(message, subject)
      Rails.logger.debug "<send_message> #{message.as_json}"
      @message = format_message(message)

      puts "<MessageOrderMailer.send_mess> Отправляем сообщение."
      mail(subject: subject) do |format|
        format.html { render "mail_mess" }
      end

      #puts "#{SiteProps.first.mail_to}"
    end

    # private

    def format_message(message)
      
      tmp = Settings.first.message_text
      if tmp.present?
        m = tmp
      end
      Rails.logger.debug "<format_message> m: #{m}"
      
      tmp = m.gsub!('{name}',message.name)
      if tmp.present?
        m = tmp
      end
      Rails.logger.debug "<format_message> m: #{m}"

      tmp = m.gsub!('{email_or_phone}',message.email_or_phone)
      if tmp.present?
        m = tmp
      end
      Rails.logger.debug "<format_message> m: #{m}"

      tmp = m.gsub!('{comment}',message.comment)
      if tmp.present?
        m = tmp
      end
      Rails.logger.debug "<format_message> m: #{m}"

      tmp = m.gsub!('{subj_id}',message.subj_id.to_s)
      if tmp.present?
        m = tmp
      end
      Rails.logger.debug "<format_message> m: #{m}"

      message.update(:comment => m)
      m
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
c80_order_form-0.1.0.11 app/mailers/c80_order_form/message_order_mailer.rb