I have a design question that I hope someone can help shed some light on. I have a view file which generates a chart. Before it can generate the chart, it needs the input from an XML file. I have a method in my controller which will generate the XML file and write it on to the disk. What I'm struggling with is how to accomplish these two steps with one link/button click from the view file. In other words, when I click the link, it will take me to the controller method which generates the XML file, write to the disk and then pass the control to the view file that will generate the chart and present the view. Where I am at: When I generate the XML using the Builder Template (rxml), it will not only write the XML output to the disk but also output the content to the view. I can't think of a way to pass the control to another view (rhtml) file that will generate the chart. And also I would like to suppress the screen output of the XML file from the Builder template, so that the generating of XML file will be transparent to the user. Essentially what should happen is a user click the link, he/she gets the chart back, and will not see the XML output. Not sure if this makes any sense at all. Many thanks for any input.
on 2007-07-25 01:36
on 2007-07-25 02:59
how exactly are you writing the output of the rxml to disk? would not a redirect_to :the_view_you_want work?
on 2007-07-25 03:01
not sure if my reply made it through, so here it is again: how exactly are you writing the results of the rxml to disk? would not a redirect_to :the_view_you_want work?
on 2007-07-25 03:27
on 2007-07-25 03:38
There's a Rails plugin called ZiYa that does XML based charting. It uses Flash (actually the SWF/Charts product) and it's really, really nice. Maybe look into that too.
on 2007-07-25 04:33
> Once you have returned a response you have no way to inject another > request from within your application. My suggestion is to make use of What I got from his description is that the link should reference the first action that writes XML to a file, and then redirect to the action that renders the view with the chart. -- Obie Fernandez http://jroller.com/obie/ Pre-order my book The Rails Way today! http://www.amazon.com/dp/0321445619
on 2007-07-25 04:36
Thank you all for your response. jemminger , This thread showed me how to write RXML output to the disk: http://groups.google.com/group/rubyonrails-talk/br... The redirect_to doesn't work in this situation because I have to render the rxml template in order to get the xml output. (at least the limitation might be my ROR knowledge level. I'm still pretty new to ROR). Robert, Perhaps Ajax might be a way of doing it. I have not got into Ajax yet, Maybe this might be the time to jump into it. Brian, Thanks for the tips. At quick glance, it certainly look interesting. Will definitely check Ziya out. By the way, perhaps a bit more information on what I'm trying to do. I'm basically trying to see if I could implement Simile Timeline in ROR. Other than this problem that I have encountered, I have also encountered other issue incorporating Timeline into ROR. So it is still an uphill process for me. Definitely a good learning exercise.
on 2007-07-25 04:39
Obie, Looks like we were both posting at the same time. Yes, you are right. That is exactly what I'm trying to do.
on 2007-07-25 05:04
Fundamentally, you just need to decouple the XML generation and writing to the disk from the rendering of the view. Thinking about it some more, you shouldn't even need a redirect. Of course, this assumes that you're hosted on one server, not a cluster I'm short on time, so all i can offer you is some pseudo-code def action xml = Builder::XmlMarkup.new(:indent => 2) craft the xml doc, just like you would in an .rxml template File.open(RAILS_ROOT+"/myfile.xml", 'w+') do |f| f.write xml.target! end # render or redirect, doesn't matter end hope it helps! On 7/24/07, maestro777 <firstname.lastname@example.org> wrote: > -- Obie Fernandez http://jroller.com/obie/ Pre-order my book The Rails Way today! http://www.amazon.com/dp/0321445619
on 2007-07-25 05:21
There's also both render_to_string (http://caboo.se/doc/classes/ ActionController/Base.html#M004346) and erase_results (http://caboo.se/ doc/classes/ActionController/Base.html#M004362) that would allow you to perform the first render and then redirect or render a second time. But, I do believe that Obie's direction of decoupling the xml generation is the right idea. nkryptic