下载XML文件而不是使用Builder进行渲染 [英] Downloading XML file instead of rendering using Builder
问题描述
我当前正在使用Builder进行自定义XML导出。但是,当用户单击按钮时,我希望下载.xml而不是进行渲染。
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.
我尝试使用 send_data
而不是 render
,但是似乎已被构建器覆盖。
I have tried using send_data
instead of render
but that seems to be overridden by builder.
还使用ActiveAdmin(因此 member_action
)
Also using ActiveAdmin (hence the member_action
)
在我的控制器中:
member_action :show do
@listing = Listing.find(params[:id])
respond_to do |format|
format.html
format.xml
end
end
链接到show.xml.builder
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 /
推荐答案
您是否尝试过这样的事情
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
这篇关于下载XML文件而不是使用Builder进行渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!