O'Reilly logo

Crafting Rails 4 Applications, 2nd Edition by José Valim

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exploring ActionController::Responder

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required