ruby-on-rails - 使用 ActionText 创建电子邮件:将 #LASTNAME 等占位符替换为数据库中的实际值
问题描述
我正在使用 rails ActionText 为所有参与者创建培训邀请电子邮件。这些电子邮件包含有关培训的自定义附件(例如培训日期/时间等),还包含某种称呼,例如
亲爱的#first_name
当以电子邮件的形式发送这些邀请时,我想将占位符 #first_name 替换为数据库中的实际名称。
@training.action_text_invitation_text.body.to_s.gsub('#first_name', 'John')
问题:输出 get 转换为 String 类,并且不再输出自定义附件的内容(只是<action-text-attachment>
,但没有内容。方法也是如此to_html
。
我一直在考虑扩展 ActionText::Content 类。但不确定如何做到这一点?
module ActionText
class Content
def custom_render
... replace the certain keywords
end
end
end
解决方案
您可以使用ActionText::Rendering.render。或者,您可以使用液体宝石或更专用的东西。
推荐阅读
- django - Django:如何将 2 个表单集合并为一个,以便在模板中显示为一个内联表(当然还有分页)
- bash - 如何遍历目录和子目录并获取父目录的名称?
- javascript - 使用 React 路由器重定向
- javascript - 如何在 React 中渲染同一类的多个对象?(如 Instagram、Facebook 或 Pinterest)
- three.js - three.js getObjectByName() 导致未定义
- node.js - Postgres results.rows[0] 未定义
- c# - 在使用 C++/CX 库的 CppWinRT 运行时组件中创作 API 的项目配置
- loopbackjs - 如何在环回中应用过滤器,同时通过“hasMany”关系包含另一个模型?
- bash - 如何使用 Bash 调用 redis-cli get?
- angular - 如何以角度选择具有ng-content的第n个孩子