Unusual rendering behavior with render_to_string()

I have an app. where I am generating PDF files. I use a .rxml template
to generate content that I then write to a file using
render_to_string().

That works fine, however, if I make a call to render(:text => ‘blah’)
afterwards, I see an error that makes it look like the render is
identifying the response as XML, even though render_to_string is not
supposed to affect the action response to the browser.

Here’s my code:

File.open(pdfgen.xfdf_file, "w") do |f|
  f.write(render_to_string(:layout => false))
end

begin
  pdfgen.generate_pdf
rescue
  return render(:text => 'There was an error generating your quote', 

:layout => false)
end

If the rescue clause runs, I get this:

"XML Parsing Error: syntax error
Location: http://localhost:3001/artisan_qualifiers/2805/print_quote
Line Number 1, Column 1:

There was an error generating your quote"

However, if I comment the call to render_to_string out, the text will
generate normally. Almost as if the call to render_to_string somehow
caused some internal flag to be set that the response would be XML, even
though it won’t.

So, two questions:

  1. Does render_to_string() modify the response even though the API docs.
    say that it doesn’t?

  2. Is there an alternative/better way to render the output of my RXML
    file to another file?

Thanks,
Wes

I forced the Content-Type to “text/plain” like so, and that work’s well.

  headers["Content-Type" ] = 'text/plain'

Wes

Wes,

How did you force the content headers? I’m having an unrelated
problem in that I have a Rails view that’s being returned as text/
plain instead of text/html. So I was wondering if I could force it to
text/html. Do you know how to do that in a Rails app?

Thanks,

Zeff

On Nov 10 2006, 4:32 am, Wes G. [email protected]

I’ve removed that code since - so I don’t have an example from my app.
anymore, but if memory serves, you should just be able to put a line
like that into your controller action.

Wes

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs