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 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
call(env) click to toggle source
     # 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
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 150
150:     def self.inherited(base)
151:       base.middleware_stack = self.middleware_stack.dup
152:       super
153:     end
middleware() click to toggle source
     # File lib/action_controller/metal.rb, line 159
159:     def self.middleware
160:       middleware_stack
161:     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, &block) click to toggle source
     # File lib/action_controller/metal.rb, line 155
155:     def self.use(*args, &block)
156:       middleware_stack.use(*args, &block)
157:     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 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
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 128
128:     def response_body=(val)
129:       body = val.respond_to?(:each) ? val : [val]
130:       super body
131:     end
status() click to toggle source
     # File lib/action_controller/metal.rb, line 120
120:     def status
121:       @_status
122:     end
status=(status) click to toggle source
     # File lib/action_controller/metal.rb, line 124
124:     def status=(status)
125:       @_status = Rack::Utils.status_code(status)
126:     end
to_a() click to toggle source

: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
url_for(string) click to toggle source

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.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.