Skip to content

Instantly share code, notes, and snippets.

@walidvb
Last active November 5, 2021 13:54
Show Gist options
  • Save walidvb/b02c7485bb2c9e578157ba5e55bd2c6f to your computer and use it in GitHub Desktop.
Save walidvb/b02c7485bb2c9e578157ba5e55bd2c6f to your computer and use it in GitHub Desktop.
class ApplicationMailer < ActionMailer::Base
def self.add_templates(template_names, block = -> {})
template_names.each do |key|
define_method(key) do
end
end
define_method(:template_name, &block)
end
end
class ExportMailer < ApplicationMailer
add_templates Export.destinations.keys, -> {
# @export is nil,
# as this seems to be called from the class, not the instance of ExportMailer
@export.type
}
def send_export(export_id)
@export = Export.find(export_id)
@user = @export.user
mail(to: @user.email, subject: subject, template_name: template_name)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment