How can I use ActionPack to render rhtml OUTSIDE of a controller ?

Hi everyone,

In my application (for producing pdf reports), I need to render some rhtml templates to html files on the disk, because I then push them through apache fop and css2xslfo to produce a neat (not so little) pdf out of my html+css combo, ready for print :). That said, the whole process of calculating the figures, rendering the html and then producing the pdf takes about 5min on my dev box, and still about 2min on my production server. Needless to say, I want this to run in a BackgrounDrb worker (thx for this wonderful plugin btw :slight_smile:

Since rendering the html file alone takes up almost 1 minute (intense db and svg image creation included), I need to put this call to ActionController#render in a background worker. As there is no way to access the controller in a backgroundrb worker (as far as i know), I am looking for a generic way to use ActionPack/View outside of a Rails controller. Currently I have a rather ugly approach, that lets me render my templates/partials from anywhere (from my model class atm) BUT, layouts don't work, since they seem to be implemented in ActionController. My current code is as follows:

  def render(options, assigns = {})

      ActionView::Base.class_eval do         require 'rubygems'         require 'RMagick'         require 'scruffy'         require 'application'

        include ApplicationHelper         include Admin::AdminHelper         include Admin::ReportsHelper         include Admin::SurveyCalculationsHelper       end

      viewer =, assigns,       viewer.render options   end

As I said, ugly! With all those class_eval includes and requires, a call to the above render method, correctly renders my partial (along with local vars passed). However, my partials yield to different places in the layout, using content_for, so it's not convenient to just wrap my partial code with what is now the layout file.

Does anyone know how to do ActionController style render with layout/ partial/localvar support outside of a ActionController instance?

Any help appreciated!

Martin Gamsjaeger