Reputation: 1853
I have the following problem which ripped my soul for the past 2 weeks:
I want to create reports with pre-rendered 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
following the ERB documentation. But inside the template file DEFAULT.HTML.ERB it sems like i only can see local variables like
content_for_prerendering = Report.get_content
not instance variables. it is very unusual to bind every instance variable to local just to render some html. Am i missing something?
Upvotes: 0
Views: 964
Reputation: 8884
try this to get view context binding to delegate instance vars correctly
@report.body = render_to_string :file => "#{Rails.root}/app/views/report_template/default.html.erb"
Upvotes: 1