Rails 3 Headers

Wow, what a great site! Hope this question meets the requirements :-)

Typically, this question is about how to set response headers in Rails using the render method. In particular, I have a discounted version of a document that I would like the browser to save as the default file rather than displaying it. I found that you can set headers using the head method, for example:

 respond_to do |format| format.html {... format.text { head(:content_disposition => "attachment") } end 

But render options don't work like that, and I can't find anything to access the headers in advance from the controller. Can anyone offer advice?

Thanks for taking the time to read my question.

+4
source share
2 answers

yes use the #headers method

 respond_to do |format| format.html {... format.text do headers[:content_disposition] = "attachment; filename=\"filename.ext\"" render... end end 
+2
source

I was not sure what the answer was, but this quick search for other articles came to the following: Rails; save displayed html content in file

Is this a trick?

0
source

All Articles