在IE7中使用Pails生成Rails PDF

在IE7中使用Pails生成Rails PDF

问题描述:

我正在使用Prawn和Prawnto在Ruby on Rails应用程序(Rails版本2.2.2)中生成PDF,该应用程序运行良好并且可以愉快地生成PDF并将其发送给用户以在Firefox中下载。

I'm using Prawn and Prawnto to generate a PDF in a Ruby on Rails app (Rails version 2.2.2) which works great and generates PDFs happily and sends them to the user to download in Firefox.

问题出在IE7中。

我的路线设置如下:

map.invoice_pdf '/invoices.pdf', :controller => 'invoices', 
                :action => 'index', :format => 'pdf'

然后我有一个像这样的链接来打电话:

Which I then have a link like so to call:

invoice_pdf_path(:year => params[:year], :month => params[:month], 
                 :unpaid_only => params[:unpaid_only])

以下在我的控制器中:

 def index
    params[:year]  = default params[:year]
    params[:month] = default params[:month]
    params[:page] ||= 1

    @invoices = Arobl.find_invoices_for_customer(current_customer.strCustomerID,
                       params)

    respond_to do |format|
      format.html{ render :action => 'index' }
      format.pdf{
        prawnto :inline => false, :filename => 
                "#{current_customer.strCustomerID}_invoice.pdf"
  end

In FF按预期工作,当单击链接时,将以.pdf格式调用show动作,并使用正确命名的PDF进行响应。当它被IE7命中时它表示无法找到文件或网站,并引用invoices.pdf而不是预期的customer_id_invoice.pdf文件名。

In FF this works as expected, when the link is clicked the show action is invoked with a format of .pdf, and responds with the correctly named PDF. When it's hit with IE7 it says that the file or website could not be found, and references "invoices.pdf" instead of the expected customer_id_invoice.pdf filename.

任何想法什么可能导致这种行为?

Any idea what could be causing this behaviour?

谢谢!

As一个临时解决方案,我使用了这里记录的方法: http://chelsearobb.wordpress.com/2009/09/09/saving-a-prawn-pdf-to-file/ 只需在本地保存文件,使用send_data和File.read,然后删除似乎在所有浏览器中都能正常工作的文件。

As an interim solution, I used the approach documented here: http://chelsearobb.wordpress.com/2009/09/09/saving-a-prawn-pdf-to-file/ and just save the file locally, use send_data and a File.read, and then delete the file which seems to work fine in all browsers.

我仍然很好奇为什么它以前在IE7中不起作用。

I'm still curious as to why it wouldn't work in IE7 previously though.