ActionController::Renderer

Episode #36 by Teacher's Avatar David Kimura

Summary

ActionController::Renderer allows you to render arbitrary templates without requirement of being in controller actions.
rails view websockets render 4:40

Resources

Summary

# irb
Application.controller.render(
  template: 'orders/index'
end

ApplicationController.render('orders/index')
OrdersController.render('index')

Available Renders

:template
:plain
:action
:html
:partial
:json
:file
:js
:inline
:xml

# irb
users = Users.all
UsersController.render('index', assigns: { users: users }, layout: false).squish

# irb
user = User.first
UsersController.render(partial: 'user', locals: { user: user }).squish

# irb
ApplicationController.renderer.defaults
renderer = ApplicationController.renderer.new(method: 'post', https: true)
renderer.render partial: 'users/user', locals: { user: user}