def partial_method(locations, locals)
      raise "No possible locations!" if locations.empty?
      partial_name = locations.delete_at 0

      new_method = lambda do |block, *args|
        if params[:format] == "pdf"
          invoke_partial partial_name, *args, &block
        else
          concat_partial partial_name, *args, &block
        end
      end

      begin
        new_method.call nil, locals
      rescue ActionView::MissingTemplate
        if locations.empty?
          raise
        else
          new_method = partial_method locations, locals
        end
      end

      new_method
    end
def partial_method(locations, locals)
      raise "No possible locations!" if locations.empty?
      partial_name = locations.delete_at 0

      new_method = lambda do |block, *args|
        if params[:format] == "pdf"
          invoke_partial partial_name, *args, &block
        else
          concat_partial partial_name, *args, &block
        end
      end

      begin
        new_method.call nil, locals
      rescue ActionView::MissingTemplate
        if locations.empty?
          raise
        else
          new_method = partial_method locations, locals
        end
      end

      new_method
    end
Utility method to create and invoke a Proc which will concat the
 partial given the possible locations.  The Proc is then returned
 so it can be added as a new method for caching purposes (otherwise
 method_missing will have to be invoked each time the partial is
 invoked).  The locations parameter is modified in the process.
 This is used by method_missing.