[英]Downloading XML file instead of rendering using Builder
I am currently using Builder to make a custom XML export. 我目前正在使用Builder进行自定义XML导出。 However when the user clicks the button I want the .xml to download instead of rendering.
但是,当用户单击按钮时,我希望下载.xml而不是进行渲染。
I have tried using send_data
instead of render
but that seems to be overridden by builder. 我试过使用
send_data
而不是render
但是似乎被builder覆盖了。
Also using ActiveAdmin (hence the member_action
) 也使用ActiveAdmin(因此,
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 链接到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/ 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.