# Render ERB templates via script/runner

**URL:** <https://www.ruby-forum.com/t/render-erb-templates-via-script-runner/175242>\
**Category:** Rails\
**Created:** [September 10, 2009, 5:36am UTC](https://www.ruby-forum.com/t/render-erb-templates-via-script-runner/175242 "2009-09-10T05:36:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdevine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9bd4f/32.png) [@jdevine](https://www.ruby-forum.com/u/jdevine)\
**Post date:** [September 10, 2009, 5:36am UTC](https://www.ruby-forum.com/t/render-erb-templates-via-script-runner/175242/1 "2009-09-10T05:36:08Z")

</div>

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: (  
[http://www.swombat.com/rails-rendering-templates-outside-of-a-contro](http://www.swombat.com/rails-rendering-templates-outside-of-a-contro)  
) which is essentially:

def render\_erb(template\_path, params)  
view = ActionView::Base.new(ActionController::Base.view\_paths,  
{})

```
class << view
 include EmailHelper, ApplicationHelper, WhateverHelper
end

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

```

params)  
end

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  
context?

Thanks for any ideas,

John Devine

---

<div class="post-metadata">

**Author:** ![jdevine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b9bd4f/32.png) [@jdevine](https://www.ruby-forum.com/u/jdevine)\
**Post date:** [September 11, 2009, 11:54pm UTC](https://www.ruby-forum.com/t/render-erb-templates-via-script-runner/175242/2 "2009-09-11T23:54:32Z")

</div>

bump…?
