[英]ERB template can`t get instance variables from the controller action:
在过去的两个星期中,我遇到了以下困扰我的灵魂:
我想使用预渲染的html-body创建报告:
def new
@content_for_prerendering= Report.get_content
@report = Report.new
template = ERB.new(File.read("#{Rails.root}/app/views/report_template/default.html.erb"))
@report.body = template.result(binding)
end
遵循ERB文档。 但是在模板文件DEFAULT.HTML.ERB中,就像我只能看到局部变量一样
content_for_prerendering = Report.get_content
不是实例变量。 将每个实例变量绑定到本地只是为了渲染一些HTML是非常不寻常的。 我想念什么吗?
尝试此操作以将视图上下文绑定正确地委派给实例var
@report.body = render_to_string :file => "#{Rails.root}/app/views/report_template/default.html.erb"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.