module Pjax
  extend ActiveSupport::Concern

  included do
    layout proc { |c| pjax_request? ? pjax_layout : nil }
    helper_method :pjax_request?

    before_filter :strip_pjax_param, :if => :pjax_request?
    before_filter :set_pjax_url,     :if => :pjax_request?
  end

  protected
    def pjax_request?
      env['HTTP_X_PJAX'].present?
    end

    def pjax_layout
      false
    end

    def pjax_container
      return unless pjax_request?
      request.headers['X-PJAX-Container']
    end

    def strip_pjax_param
      params.delete(:_pjax)
      request.env['QUERY_STRING'] = Rack::Utils.build_query(params)

      request.env.delete('rack.request.query_string')
      request.env.delete('rack.request.query_hash')
      request.env.delete('action_dispatch.request.query_parameters')

      request.instance_variable_set('@original_fullpath', nil)
      request.instance_variable_set('@fullpath', nil)
    end

    def set_pjax_url
      response.headers['X-PJAX-URL'] = request.url
    end
end

module Pjax
  extend ActiveSupport::Concern

  included do
    layout proc { |c| pjax_request? ? pjax_layout : 'application' }
    helper_method :pjax_request?

    before_filter :strip_pjax_param, :if => :pjax_request?
    before_filter :set_pjax_url,     :if => :pjax_request?
  end

  protected
    def pjax_request?
      env['HTTP_X_PJAX'].present?
    end

    def pjax_layout
      false
    end

    def pjax_container
      return unless pjax_request?
      request.headers['X-PJAX-Container']
    end

    def strip_pjax_param
      params.delete(:_pjax)
      request.env['QUERY_STRING'] = Rack::Utils.build_query(params)

      request.env.delete('rack.request.query_string')
      request.env.delete('rack.request.query_hash')
      request.env.delete('action_dispatch.request.query_parameters')

      request.instance_variable_set('@original_fullpath', nil)
      request.instance_variable_set('@fullpath', nil)
    end

    def set_pjax_url
      response.headers['X-PJAX-URL'] = request.url
    end
end

Revert "nil layout should fallback to application"
Revert "nil layout should fallback to application"

This reverts commit 4e6505e26cf398591247bd3e7137e10f955ba18f.
