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 176 176: def self.action(name, klass = ActionDispatch::Request) 177: middleware_stack.build(name.to_s) do |env| 178: new.dispatch(name, klass.new(env)) 179: end 180: end
# File lib/action_controller/metal.rb, line 163 163: def self.call(env) 164: action(env['action_dispatch.request.path_parameters'][:action]).call(env) 165: 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 150 150: def self.inherited(base) 151: base.middleware_stack = self.middleware_stack.dup 152: super 153: end
# File lib/action_controller/metal.rb, line 159 159: def self.middleware 160: middleware_stack 161: 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 134 134: def dispatch(name, request) 135: @_request = request 136: @_env = request.env 137: @_env['action_controller.instance'] = self 138: process(name) 139: to_a 140: 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 128 128: def response_body=(val) 129: body = val.respond_to?(:each) ? val : [val] 130: super body 131: end
# File lib/action_controller/metal.rb, line 120 120: def status 121: @_status 122: end
# File lib/action_controller/metal.rb, line 124 124: def status=(status) 125: @_status = Rack::Utils.status_code(status) 126: end
:api: private
# File lib/action_controller/metal.rb, line 143 143: def to_a 144: response ? response.to_a : [status, headers, response_body] 145: end
basic url_for that can be overridden for more robust functionality
# File lib/action_controller/metal.rb, line 116 116: def url_for(string) 117: string 118: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.