Render ERB templates via script/runner

Is there an approved, easy way to generate files via erb templates
through script/runner?

I need to generate a set of html files offline (via a cron job). I
would like to use script/runner and use an erb template with various
helpers and partials that I’ve already written.

Googling yields one suggestion: (
) which is essentially:

def render_erb(template_path, params)
view =,

class << view
 include EmailHelper, ApplicationHelper, WhateverHelper

view.render(:file => "#{template_path}.html.erb", :locals =>


But… this only works in simple cases and even then fails when called
via script/runner with nil.content_type errors.

Looking at how ActionMailer does its work it seems that there are a
whole lot of hoops that are being jumped through to stub out
ActionController expectations…

So the question is, has anyone done this work already? Perhaps
distilled ActionMailer’s strategy’s for use outside of the mailing

Thanks for any ideas,

John Devine


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs