问题
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/
回答1:
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
来源:https://stackoverflow.com/questions/18653336/downloading-xml-file-instead-of-rendering-using-builder