Forum: Ruby on Rails How can I use ActionPack to render rhtml OUTSIDE of a contro

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Martin G. (Guest)
on 2007-02-25 03:55
(Received via mailing list)
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 :)

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

      viewer =, assigns,
      viewer.render options

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 G.
This topic is locked and can not be replied to.