Ash*_*rlc 2 template-engine ruby-on-rails liquid ruby-on-rails-3
我得到了Liquid error: undefined method 'to_liquid' for #<Email:0x007f9ca1a62d28>我的错误Email发送使用视图内的液体模板的电子邮件时对象.但是,当我在浏览器中自己渲染视图时,它工作得很好!
这是我的观点:
= raw @template.render('email' => @email, 'organization' => @organization)
%p= sanitize("<a href='{{ unsubscribe_url }}''>Click here to unsubscribe</a>")
%p{style:'text-align:center;'}
Sent with
= link_to 'Vocalem', 'http://vocalem.com'
Run Code Online (Sandbox Code Playgroud)
我的邮件的相关部分:
class BulkMailer < ActionMailer::Base
def bulk_email(recipients, email, organization)
...
@organization = organization
@email = email
@template = Liquid::Template.parse(organization.current_email_template.body)
Run Code Online (Sandbox Code Playgroud)
相关型号代码:
liquid_methods :subject, :body, :id
Run Code Online (Sandbox Code Playgroud)
最后但并非最不重要的是,Liquid的一个例子给出了错误(但在普通视图中正常工作!):
{{email.body}}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,{{organization.display_name}}不会抛出错误,但在电子邮件中只是完全空白(尽管在普通视图中再次正常工作).
任何线索可能会发生在这里?
尝试使用组织模型中的to_liquid创建流动方法并进行检查
def to_liquid
{
'display_name'=>self.name,
'email_body'=>self.current_email_template.body
}
end
Run Code Online (Sandbox Code Playgroud)