So, if anyone is interested, I made a small, simple rails application
that demonstrates what I'm trying to do (sort of), how I'm trying to
do it, and how it fails. It has all gems it requires bundled. You just
need ruby, rails 2.3.5, and sqlite3 to run it.

http://tinyurl.com/ygqvwt4

The real issue is that I can see no way to actually force or tell
#render_to_string to render a "type" specified by me that differs from
the requested "format".

The application has a worksheets controller/model/etc with only two
extra, custom actions added: #print and #email. To get it to work,
you'll need to define/replace the constants (tagged with TODO) acting
as placeholders in the app/controllers/worksheets_controller.rb file.

In order to demonstrate that you CAN in fact use #render_to_string (if
the underlying request's format/type is already of the desired type)
to use prawnto to render a PDF to a string that you can then attach to
a PDF, I duplicated some of the code in the #email method in the
#print method. So, if you create a "worksheet" then "view" the
worksheet and click the "print" link, it will render and display a PDF
successfully as well as render a copy that will be sent to you as an
email attachment.

However, if you try to accomplish this by clicking "Email" the #email
method's identical code that calls #render_to_string will fail since
the type/format isn't for a PDF (application/pdf or whatever). It
instead fails as it wants to find an erb template (that doesn't
exist).

So, what I'm really trying to do here isn't necessarily prawn/prawnto
specific. I just want to be able to call #render_to_string in a
controller to render an action (the same or another action) using a
manually specified "type" (rjs, pdf, yourmom, whatever). Is there a
way to do this and I'm just missing it? I've been reading the source
and it appears the answer is I'll have to monkey-patch (doh).

Anyhow, if anyone also has any other good recommendations on how to
keep controllers DRY when you need to do something like what I'm
trying to do here, feel free to chime in.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to