views:

54

answers:

1

I want to render an HTML-EMail and send it to our customers using some ERB Templates.

The basic code I am using:

ERB.new("newsletter.html.erb").result(binding)

doesn't allow me to add partials to the html.erb-File. I would love to move the header and footer to a partial and use the render :partial-Method in that call.

Is this possible? What do I have to add?

A: 

This is what I came up with:

viewer = ActionView::Base.new(File.join(Rails::Configuration.new.view_path, "PATH/TO/PARTIALS"))
html = viewer.render(
    :file => "PATH/TO/FILE.ERB), 
    :locals => {:variable => @var}
)

please correct me if there is a more elegant solution than this.

bitboxer