Module: Pageflow::ControllerDelegation Private

Included in:
EntriesController, RevisionsController
Defined in:
app/controllers/concerns/pageflow/controller_delegation.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Allow delegating to another Rack app from a controller action.

Instance Method Summary collapse

Instance Method Details

#delegate_to_rack_app!(app) {|result| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Abort currently executed controller action, call passed Rack app and use its response instead. A block can be passed to mutate the response.

Yields:

  • (result)


9
10
11
12
13
14
# File 'app/controllers/concerns/pageflow/controller_delegation.rb', line 9

def delegate_to_rack_app!(app)
  result = app.call(request.env)
  yield(*result) if block_given?

  throw(:delegate, result)
end

#dispatchObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Override ActionController::Metal#dispatch [1] which returns the Rack response triple generated by the controller. Calling ‘delegate_to_rack_app!` aborts execution of the current controller action and returns the response of the given Rack app instead.

The second argument passed to ‘throw` is becomes the return value of `catch`. If `throw` is not called, `catch` passes the return value of its block.

1

github.com/rails/rails/blob/8bec77cc0f1fd47677a331a64f68c5918efd2ca9/actionpack/lib/action_controller/metal.rb#L188



27
28
29
# File 'app/controllers/concerns/pageflow/controller_delegation.rb', line 27

def dispatch(*)
  catch(:delegate) { super }
end