Home Generate XML file and redirect to other view with Rails
Reply: 1

Generate XML file and redirect to other view with Rails

Juan Fernandez Sosa
Juan Fernandez Sosa Published in 2017-11-13 15:41:30Z

I have a piece of code that generates an XML file. What I want to, and didn't find the solution, is to generate the XML file and ALSO redirect to another page, to give a feedback message.

My code is

def exportFiles
    recursive_tree= GitHubRepositorioService.getRecursiveTree('master')
    GitHubService.updateFiles(@files, recursive_tree)
    xml = Builder::XmlMarkup.new(:target=>$stdout, :indent=>2)
    respond_to do |format|
     format.xml { send_data render_to_string(:exportFiles), filename: 'exported_module.xml', type: 'application/xml', disposition: 'attachment' }

As I already use "respond_to" I can't use another redirect sentence... so, there is a way to generate (downloading) that file and redirect to other view?

Samy Kacimi
Samy Kacimi Reply to 2017-11-13 15:46:42Z

Unfortunately, this is not possible via the controller as you can't send two responses.

But you could do this via javascript for instance. See this topic for more info Rails how do I - export data with send_data then redirect_to a new page?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.333739 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO