0

I'm hitting this bug in my application, where ajax in mobile safari stops working after receiving a response with Content-Disposition:attachment

I want to keep sending disposition:attachment to desktop browsers and to non-iOS mobile devices, while switching to disposition:inline on iOS. I need to do this in a few different controller actions.

Is there an elegant way of doing this beyond putting these types of blocks all over the place?

if request.env['HTTP_USER_AGENT'] =~ /iPad/
    disposition = :inline
else 
    disposition = :attachment
end
4

1 に答える 1

2

before_filter一度だけ設定するアプリケーションコントローラーを作成するだけです!

class ApplicationController < ActionController::Base
  before_filter :set_content_disposition

  def set_content_disposition
    if request.env['HTTP_USER_AGENT'] =~ /iPad/
      response.headers['Content-Disposition'] = 'inline'
    elsif params[:format].in?(['pdf', 'other_format', 'other_format2'])
      response.headers['Content-Disposition'] = 'attachment'
    end
  end
  #Rest of application controller code ...
end
于 2012-08-02T16:07:53.733 に答える