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
1#
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
    @files=FileToExport.getComponentToExport
    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' }
    end
    FileToExport.setComponentToExport(nil)
  end

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
2#
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.319936 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO