加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 如何在模型中使用Sinatra的Haml-helper?

发布时间:2020-12-17 03:52:27 所属栏目:百科 来源:网络整理
导读:在我的一个模型中,我有一个发送电子邮件的方法.我想通过Haml文件标记此电子邮件,该文件与我的其他视图一起存储. 有没有办法从模型中调用Sinatra的HAML帮助器?如果没有,我需要直接打电话给Haml: @name = 'John Doe'Haml::Engine.new(File.read("#{MyApplica
在我的一个模型中,我有一个发送电子邮件的方法.我想通过Haml文件标记此电子邮件,该文件与我的其他视图一起存储.

有没有办法从模型中调用Sinatra的HAML帮助器?如果没有,我需要直接打电话给Haml:

@name = 'John Doe'
Haml::Engine.new(File.read("#{MyApplication.views}/email.haml")).to_html

Haml模板有没有办法访问@name实例变量?

解决方法

尝试这样的事情:

tmpl = Tilt.new("#{MyApplication.views}/email.haml")
tmpl.render(self) # render the template with the current model instance as the context

希望这可以帮助!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读