Hello, my question is rails related though it is also somewhat
specific to the prawnto plugin (installed latest version as of
2010-03-15). I would ask on a prawnto forum/list if I knew where one
was.
Anyhow, I’m using rails 2.3.5 (with ruby 1.8.6 patchlevel 111) in an
app that is successfully using the prawnto gem (with the prawn gem
version 0.7.1). I’ve got a a WorksheetsController with the standard
scaffold actions (and associated routes). I was able to drop in a
“show.pdf.prawn” file into the associated view directory, write some
prawn code in it, and add a “format.pdf { render :layout => false }”
line inside the #show method’s “respond_to” block. After doing this I
could “view” my worksheets as PDF documents by adding a “.pdf”
extension/type-definition to the end of the url:
http://localhost/worksheets/1.pdf
This is great. However, now I need to add a feature where someone can
request that I email them a PDF copy of a worksheet. In the interest
of being DRY, I want to re-use all the prawn pdf generation code in my
“show.pdf.prawn” view file. After poking around, I figured
#render_to_string might do the job.
The “email request” is implemented as the #email method/action in my
controller. After grabbing the @worksheet object, I attempt to render
the PDF as follows:
worksheet = render_to_string :action => “show”, :layout =>
false, :type => :prawn
The #email action is always called via AJAX. Also, I have some AJAX
stuff implemented for the #show action as show.rjs. The
#render_to_string always renders the show action’s RJS template,
ignoring the :type => :prawn setting.
So, clearly I have a misunderstanding #render_to_string. I’m also
wondering if there is a better way to accomplish what I need to do.
Any ideas?