1
votes

I'm using the prawn-rails gem to generate a pdf and am setting the filename by overwriting the @filename variable in my controller eg:

respond_to do |format|
  format.pdf do
    @filename = "NewReportName.pdf"
    render 'report'
  end
end

I am then using the following view to generate the pdf:

data_rows = [@report.fields.map{|f| f.titleize }]

@report.results.each do |result|
  data_rows << @report.fields.map{|k| result.send(k) }
end

prawn_document() do |pdf|
  pdf.table(data_rows)
end

The pdf generation works in all browsers I've tested however when you go to save the pdf in IE11, it sets the filename to be the action name instead of the name specified in the @filename variable.

I've posted a comment on the git repo for the prawn-rails gem but I'm wondering if anyone here could help. Thanks in advance.

1
You might set it explicitly. render 'report', disposition: 'attachment', filename: @filename... Not 100% sure about the syntax, but you get the idea... - Ruby Racer
I've tried setting the headers in the controller, but that didn't solve it. eg: response.headers['Content-Disposition'] = "attachment; filename=\"NewReportName.pdf\"" - chrisgooley

1 Answers

0
votes

You can set the file name using prawnto

format.pdf do
  @filename = "NewReportName.pdf"
  prawnto :filename=>@filename
end