开发者

Rails 3 response headers

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 an开发者_StackOverflowything to access the headers beforehand from the controller. Could anybody offer advice?

Thanks for taking the time to read my question.


yes use #headers method

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


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜