Skip to content

Instantly share code, notes, and snippets.

@IlyaDonskikh
Created August 21, 2018 09:10
Show Gist options
  • Save IlyaDonskikh/c73e18d2c16196f1c517f1d6612fa0bb to your computer and use it in GitHub Desktop.
Save IlyaDonskikh/c73e18d2c16196f1c517f1d6612fa0bb to your computer and use it in GitHub Desktop.
# Иногда менеджерам требуется составлять шаблоны писем с динамическими данными.
# Поэтому требуется разработать сервис, который позволит создавать и хранить шаблоны,
# а также отправлять письма на их основе.
# Данные:
Account(balance:float currency:string name:string email:string)
Message(title:string, text:text)
# Пример сообщения: "Здравствуйте, {{name}}. Ваш баланс: {{balance}}{{currency}}".
# Пример отправки.
AccountMailer.notify(@message, @account).deliver_now
# Результат - ссылка на гитхаб репозиторий.
@iamdeuterium
Copy link

class AccountMailer < ApplicationMailer
  def notify(message, account)
    mail to: account.email, subject: inject_attributes(message.title, account) do |format|
      format.text { render text: inject_attributes(message.text, account) }
    end
  end

  private
  def inject_attributes(text, record)
    text.gsub(/{{([^{]+)}}/) { record.try($1) }
  end
end  

@ilnar4888
Copy link

doniv...@gmail.com не валиден. Если вакансия актуальна, пришлите валидный адрес на ilnar4888@gmail.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment