ActionController::Metal provides a way to get a valid Rack application from a controller.
In AbstractController, dispatching is triggered directly by calling # on a new controller. ActionController::Metal provides an # method that returns a valid Rack application for a given action. Other rack builders, such as Rack::Builder, Rack::URLMap, and the Rails router, can dispatch directly to the action returned by FooController.action(:index).
Return a rack endpoint for the given action. Memoize the endpoint, so multiple calls into MyController.action will return the same object for the same action.
action<#> | An action name |
Proc | A rack application |
# File lib/action_controller/metal.rb, line 171 171: def self.action(name, klass = ActionDispatch::Request) 172: middleware_stack.build(name.to_s) do |env| 173: new.dispatch(name, klass.new(env)) 174: end 175: end
# File lib/action_controller/metal.rb, line 158 158: def self.call(env) 159: action(env['action_dispatch.request.path_parameters'][:action]).call(env) 160: end
Returns the last part of the controller’s name, underscored, without the ending “Controller”. For instance, MyApp::MyPostsController would return “my_posts“ for controller_name
String
# File lib/action_controller/metal.rb, line 63 63: def self.controller_name 64: @controller_name ||= self.name.demodulize.sub(/Controller$/, '').underscore 65: end
# File lib/action_controller/metal.rb, line 145 145: def self.inherited(base) 146: base.middleware_stack = self.middleware_stack.dup 147: super 148: end
# File lib/action_controller/metal.rb, line 154 154: def self.middleware 155: middleware_stack 156: end
# File lib/action_controller/metal.rb, line 103 103: def content_type 104: headers["Content-Type"] 105: end
Basic implementations for content_type=, location=, and headers are provided to reduce the dependency on the RackDelegation module in Renderer and Redirector.
# File lib/action_controller/metal.rb, line 99 99: def content_type=(type) 100: headers["Content-Type"] = type.to_s 101: end
Delegates to the class’ #
# File lib/action_controller/metal.rb, line 68 68: def controller_name 69: self.class.controller_name 70: end
:api: private
# File lib/action_controller/metal.rb, line 129 129: def dispatch(name, request) 130: @_request = request 131: @_env = request.env 132: @_env['action_controller.instance'] = self 133: process(name) 134: to_a 135: end
# File lib/action_controller/metal.rb, line 107 107: def location 108: headers["Location"] 109: end
# File lib/action_controller/metal.rb, line 111 111: def location=(url) 112: headers["Location"] = url 113: end
# File lib/action_controller/metal.rb, line 87 87: def params 88: @_params ||= request.parameters 89: end
# File lib/action_controller/metal.rb, line 91 91: def params=(val) 92: @_params = val 93: end
# File lib/action_controller/metal.rb, line 123 123: def response_body=(val) 124: body = val.respond_to?(:each) ? val : [val] 125: super body 126: end
# File lib/action_controller/metal.rb, line 115 115: def status 116: @_status 117: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.