November 2013
Intermediate to advanced
200 pages
4h 31m
English
Anything that responds to call, accepting three arguments, can be a responder. The three arguments given to call are the current controller, the resource (or a nested resource or an array of resources), and a hash of options. All the options given to respond_with are forwarded to the responder as the third argument.
ActionController::Responder implements the call method in a single line of code, as we can see in the Rails source code:
| rails/actionpack/lib/action_controller/metal/responder.rb | |
| | def self.call(*args) |
| | new(*args).respond |
| | end |
The call method forwards these three arguments to the ActionController::Responder initialization and then calls respond:
| rails/actionpack/lib/action_controller/metal/responder.rb ... |