Question

I am currently using Builder to make a custom XML export. However when the user clicks the button I want the .xml to download instead of rendering.

I have tried using send_data instead of render but that seems to be overridden by builder.

Also using ActiveAdmin (hence the member_action)

In my controller:

  member_action :show do
    @listing = Listing.find(params[:id])
    respond_to do |format|
      format.html
      format.xml 
    end
  end

Links to show.xml.builder

xml.instruct!
xml.XMLopener { |b|
  b.....
  ......
  ....
  }

I have looked at a few links below but I can't seem to get it working. Any ideas? Obviously with the current code it is just rendering, which works perfectly.

https://www6.software.ibm.com/developerworks/education/x-rubyonrailsxml/x-rubyonrailsxml-a4.pdf http://danengle.us/2009/05/generating-custom-xml-for-your-rails-app/

Was it helpful?

Solution

Have you tried something like this

respond_to do |format|
  format.html
  format.xml { send_file :filename => 'mydoc.xml', :type=>"application/xml", :disposition => 'attachment' }
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top