I've got a nice XML view of my data that works just fine when I call it from the browser. Now I'd like a different controller method to take that XML and write it to the file system. Since the XML view lives in an RXML file, is there a trick to telling the controller "Get your output into a string" instead of writing it back to the browser? After writing it out to the file system I have a different page I want to write. Right now I'm actually making a Net::HTTP call to myself, but that seems to be creating a race condition.
on 2006-06-09 19:19
on 2006-06-09 19:24
Try render_to_string http://api.rubyonrails.com/classes/ActionControlle...
on 2006-06-09 19:32
Without verifying or looking up. I think this should work. xmlstring = render(:action => "xmlview").to_s On 6/9/06, Duane M. <firstname.lastname@example.org> wrote: > to be creating a race condition. > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > email@example.com > http://lists.rubyonrails.org/mailman/listinfo/rails > --
on 2006-06-09 19:32
Oh... A better and a more correct idea came forward. On 6/9/06, Jon Gretar B. <firstname.lastname@example.org> wrote: > > output into a string" instead of writing it back to the browser? After > > _______________________________________________ > --
on 2006-06-09 21:08
Ben Kittrell wrote: > Try render_to_string > http://api.rubyonrails.com/classes/ActionControlle... Aha! Neat find, thanks. Though I think this might be trickier than it first appears. You apparently can't use both "render_to_string" and "render" in the same request. So, for isntance, I cannot render my xml to a string, save it to the file system, and the go on to render a response. Since my view is an RXML file, it appears to set the returning contentType to text/xml on the render_to_string statement, which would be a mistake. Because then when I go to render my HTML results, it starts barfing wherever I have poorly formed XHTML. (I can prove this because if I render valid xml, it works fine.) This'll work for me for now, I'll just have to come up with some way (possibly via redirect) to refresh the page when done. But really I don't think that render_to_string should set the contenttype header.