Class Index [+]

Quicksearch

ActionController::Metal

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

Public Class Methods

action(name, klass = ActionDispatch::Request) click to toggle source

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.

Parameters

action<#>

An action name

Returns

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
call(env) click to toggle source
     # 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
controller_name() click to toggle source

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

Returns

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
inherited(base) click to toggle source
     # 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
middleware() click to toggle source
     # File lib/action_controller/metal.rb, line 154
154:     def self.middleware
155:       middleware_stack
156:     end
new(*) click to toggle source
    # File lib/action_controller/metal.rb, line 81
81:     def initialize(*)
82:       @_headers = {"Content-Type" => "text/html"}
83:       @_status = 200
84:       super
85:     end
use(*args) click to toggle source
     # File lib/action_controller/metal.rb, line 150
150:     def self.use(*args)
151:       middleware_stack.use(*args)
152:     end

Public Instance Methods

content_type() click to toggle source
     # File lib/action_controller/metal.rb, line 103
103:     def content_type
104:       headers["Content-Type"]
105:     end
content_type=(type) click to toggle source

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
controller_name() click to toggle source

Delegates to the class’ #

    # File lib/action_controller/metal.rb, line 68
68:     def controller_name
69:       self.class.controller_name
70:     end
dispatch(name, request) click to toggle source

: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
location() click to toggle source
     # File lib/action_controller/metal.rb, line 107
107:     def location
108:       headers["Location"]
109:     end
location=(url) click to toggle source
     # File lib/action_controller/metal.rb, line 111
111:     def location=(url)
112:       headers["Location"] = url
113:     end
params() click to toggle source
    # File lib/action_controller/metal.rb, line 87
87:     def params
88:       @_params ||= request.parameters
89:     end
params=(val) click to toggle source
    # File lib/action_controller/metal.rb, line 91
91:     def params=(val)
92:       @_params = val
93:     end
response_body=(val) click to toggle source
     # 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
status() click to toggle source
     # File lib/action_controller/metal.rb, line 115
115:     def status
116:       @_status
117:     end
status=(status) click to toggle source
     # File lib/action_controller/metal.rb, line 119
119:     def status=(status)
120:       @_status = Rack::Utils.status_code(status)
121:     end
to_a() click to toggle source

:api: private

     # File lib/action_controller/metal.rb, line 138
138:     def to_a
139:       response ? response.to_a : [status, headers, response_body]
140:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.