Rails - Force XML template to be downloaded instead of rendered



My question is very similar to this question but that answer does not work for me. I have a custom xml file that I want downloaded instead of rendered by the browser. I've tried the send_file method like the answer to the question I linked above, but I also get an error can't convert Hash into String.


Controller:



respond_to do |format|
format.tmx
end


Template: show.tmx.erb



<?xml version="1.0"?>
<tmx xmlns="http://ift.tt/1zDhre3" version="1.4b">
</tmx>


View (I want this link to download a document instead of render in the browser):



<%= link_to "Download", document_path(@document, format: "tmx") %>

No comments:

Post a Comment