Reputation: 41
Wow, what a great site! I hope this question meets the requirements :-)
Generally, this question is about how to set response headers in Rails when using the render
method. Specifically, I have a markdown version of a document, which I would like the browser to save as a file by default, rather than display. I have found that you can set headers with the head
method, like this:
respond_to do |format|
format.html {...
format.text { head(:content_disposition => "attachment") }
end
But the options for render
don't work like this and I can't find anything to access the headers beforehand from the controller. Could anybody offer advice?
Thanks for taking the time to read my question.
Upvotes: 4
Views: 9607
Reputation: 1568
yes use #headers method
respond_to do |format|
format.html {...
format.text do
headers[:content_disposition] = "attachment; filename=\"filename.ext\""
render...
end
end
Upvotes: 2
Reputation: 1676
I wasn't sure what the answer was, but this quick search of other articles came up with this: Rails; save a rendered views html content to file
Does that do the trick?
Upvotes: 0