Last active
December 13, 2015 23:59
-
-
Save gogogarrett/4996124 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def send_custom_email email, email_translation, recipient, context_variables | |
| # ... | |
| fields = %w|{{user.first_name}} {{user.last_name}} {{user.username}} {{user.site_name}} | |
| {{initiative.name}} {{initiative_methodology.name}} {{user_award.points}} {{user_award.disbursed_at}} | |
| {{user_award.reason}} {{user_award.message}} {{user_award.link}} {{file_upload_job.status}}| | |
| if recipient.present? | |
| fields.each do |f| | |
| obj = f.gsub("{{","").gsub("}}","").split('.').first | |
| field = f.gsub("{{","").gsub("}}","").split('.').second | |
| obj_instance = eval("context_variables[:#{obj}]") | |
| if obj_instance.respond_to?(:translation_for) | |
| value = obj_instance.translation_for(email_translation.locale)[field] | |
| else | |
| value = obj_instance[field] | |
| end | |
| end | |
| end | |
| # ... | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment