class ActionController::Metal
can dispatch directly to the action returned by FooController.action(:index).
given action. Other rack builders, such as Rack::Builder, Rack::URLMap, and the Rails router,
ActionController::Metal provides an #action method that returns a valid Rack application for a
In AbstractController, dispatching is triggered directly by calling #process on a new controller.
ActionController::Metal provides a way to get a valid Rack application from a controller.
def self.action(name, klass = ActionDispatch::Request)
==== Returns
action<#to_s>:: An action name
==== Parameters
for the same action.
multiple calls into MyController.action will return the same object
Return a rack endpoint for the given action. Memoize the endpoint, so
def self.action(name, klass = ActionDispatch::Request) middleware_stack.build(name.to_s) do |env| new.dispatch(name, klass.new(env)) end end
def self.call(env)
def self.call(env) action(env['action_dispatch.request.path_parameters'][:action]).call(env) end
def self.controller_name
==== Returns
controller_name
"Controller". For instance, MyApp::MyPostsController would return "my_posts" for
Returns the last part of the controller's name, underscored, without the ending
def self.controller_name @controller_name ||= self.name.demodulize.sub(/Controller$/, '').underscore end
def self.inherited(base)
def self.inherited(base) base.middleware_stack = self.middleware_stack.dup super end
def self.middleware
def self.middleware middleware_stack end
def self.use(*args, &block)
def self.use(*args, &block) middleware_stack.use(*args, &block) end
def content_type
def content_type headers["Content-Type"] end
def content_type=(type)
def content_type=(type) headers["Content-Type"] = type.to_s end
def controller_name
def controller_name self.class.controller_name end
def dispatch(name, request)
def dispatch(name, request) @_request = request @_env = request.env @_env['action_controller.instance'] = self process(name) to_a end
def initialize(*)
def initialize(*) @_headers = {"Content-Type" => "text/html"} @_status = 200 super end
def location
def location headers["Location"] end
def location=(url)
def location=(url) headers["Location"] = url end
def params
def params @_params ||= request.parameters end
def params=(val)
def params=(val) @_params = val end
def response_body=(val)
def response_body=(val) body = val.respond_to?(:each) ? val : [val] super body end
def status
def status @_status end
def status=(status)
def status=(status) @_status = Rack::Utils.status_code(status) end
def to_a
def to_a response ? response.to_a : [status, headers, response_body] end
def url_for(string)
def url_for(string) string end