class ActionController::Metal


other features you can bring into your metal controller.
You can refer to the modules included in ActionController::Base to see
== Other Helpers
end
end
redirect_to root_url
def index
include Rails.application.routes.url_helpers
include ActionController::Redirecting
class HelloController < ActionController::Metal
To add redirection helpers to your metal controller, do the following:
== Redirection Helpers
end
end
render “hello/index”
def index
append_view_path “#{Rails.root}/app/views”
include ActionView::Layouts
include AbstractController::Rendering
class HelloController < ActionController::Metal
can do the following:
add the render helpers you’re used to having in a normal controller, you
response_body=, content_type=, and status=. To
views, partials, or other responses aside from explicitly calling of
ActionController::Metal by default provides no utilities for rendering
== Rendering Helpers
router to dispatch to.
The action method returns a valid Rack application for the Rails
get ‘hello’, to: HelloController.action(:index)
something like this to config/routes.rb:
And then to route requests to your metal controller, you would add
end
end
self.response_body = “Hello World!”
def index
class HelloController < ActionController::Metal
A sample metal controller might look like this:
ActionController::Base.
valid Rack interface without the additional niceties provided by
ActionController::Metal is the simplest possible controller, providing a

def self.action(name)

Returns a Rack endpoint for the given action name.
def self.action(name)
  app = lambda { |env|
    req = ActionDispatch::Request.new(env)
    res = make_response! req
    new.dispatch(name, req, res)
  }
  if middleware_stack.any?
    middleware_stack.build(name, app)
  else
    app
  end
end

def self.action_encoding_template(action) # :nodoc:

:nodoc:
def self.action_encoding_template(action) # :nodoc:
  false
end

def self.controller_name

* string
==== Returns

Namespaces are left out, so Admin::PostsController returns posts as well.
Controller. For instance, PostsController returns posts.
Returns the last part of the controller's name, underscored, without the ending
def self.controller_name
  @controller_name ||= (name.demodulize.delete_suffix("Controller").underscore unless anonymous?)
end

def self.dispatch(name, req, res)

executes the action named +name+.
Direct dispatch to the controller. Instantiates the controller, then
def self.dispatch(name, req, res)
  if middleware_stack.any?
    middleware_stack.build(name) { |env| new.dispatch(name, req, res) }.call req.env
  else
    new.dispatch(name, req, res)
  end
end

def self.inherited(base) # :nodoc:

:nodoc:
def self.inherited(base) # :nodoc:
  base.middleware_stack = middleware_stack.dup
  super
end

def self.make_response!(request)

def self.make_response!(request)
  ActionDispatch::Response.new.tap do |res|
    res.request = request
  end
end

def self.middleware

Alias for +middleware_stack+.
def self.middleware
  middleware_stack
end

def controller_name

Delegates to the class's ::controller_name.
def controller_name
  self.class.controller_name
end

def dispatch(name, request, response) # :nodoc:

:nodoc:
def dispatch(name, request, response) # :nodoc:
  set_request!(request)
  set_response!(response)
  process(name)
  request.commit_flash
  to_a
end

def initialize

def initialize
  @_request = nil
  @_response = nil
  @_routes = nil
  super
end

def params

def params
  @_params ||= request.parameters
end

def params=(val)

def params=(val)
  @_params = val
end

def performed?

Tests if render or redirect has already happened.
def performed?
  response_body || response.committed?
end

def reset_session

def reset_session
  @_request.reset_session
end

def response_body=(body)

def response_body=(body)
  body = [body] unless body.nil? || body.respond_to?(:each)
  response.reset_body!
  return unless body
  response.body = body
  super
end

def set_request!(request) # :nodoc:

:nodoc:
def set_request!(request) # :nodoc:
  @_request = request
  @_request.controller_instance = self
end

def set_response!(response) # :nodoc:

:nodoc:
def set_response!(response) # :nodoc:
  @_response = response
end

def to_a # :nodoc:

:nodoc:
def to_a # :nodoc:
  response.to_a
end

def url_for(string)

Basic url_for that can be overridden for more robust functionality.
def url_for(string)
  string
end

def use(...)

middleware stack.
Pushes the given Rack middleware and its arguments to the bottom of the
def use(...)
  middleware_stack.use(...)
end