Ruby on rails ERB模板无法从控制器操作获取实例变量:

Ruby on rails ERB模板无法从控制器操作获取实例变量:,ruby-on-rails,erb,Ruby On Rails,Erb,在过去的两周里,我遇到了以下问题,这撕裂了我的灵魂: 我想创建具有预呈现html正文的报告: 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

在过去的两周里,我遇到了以下问题,这撕裂了我的灵魂:

我想创建具有预呈现html正文的报告:

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
遵循雇员再培训局文件。但是在模板文件DEFAULT.HTML.ERB中,我只能看到局部变量,比如

 content_for_prerendering = Report.get_content

不是实例变量。仅仅为了呈现一些html而将每个实例变量绑定到本地是非常不寻常的。我遗漏了什么吗?

尝试此操作以正确地将视图上下文绑定到委托实例变量

@report.body = render_to_string :file => "#{Rails.root}/app/views/report_template/default.html.erb"

马上就去看看!-你是说
render_to_string`因为它抱怨
render_to_text
-没有方法错误吗?这就像magick一样工作,但我选择了render_to_body
。请将您的答案更正为
render\u to\u string`或
render\u to\u body