module ActionView::Helpers::RenderingHelper

def _layout_for(*args, &block)



Hello David


would be
and the struct specified would be passed into the block as an argument. The result
In this case, the layout would receive the block passed into `render :layout`,


<%= yield Struct.new(:name).new("David") %>

# The layout

<% end %>
Hello <%= customer.name %>
<%= render layout: "my_layout" do |customer| %>
# The template

`yield`:
Finally, the block can take block arguments, which can be passed in by


Content


would be
this method returns the block that was passed in to `render :layout`, and the response
In this case, instead of the default block, which would return `content_for(:layout)`,


<%= yield %>

# The layout

<% end %>
Content
<%= render layout: "my_layout" do %>
# The template

The user can override this default by passing a block to the layout:

returns `content_for(:layout)`.
`content_for(:some_name)`. If the user calls simply `yield`, the default block
calls `yield :some_name`, the block, by default, returns
You can think of a layout as a method that is called with a block. If the user

a name or a block.
passed to a partial. Returns the contents that are yielded to a layout, given
Overrides _layout_for in the context object so it supports the case a block is
def _layout_for(*args, &block)
  name = args.first
  if block && !name.is_a?(Symbol)
    capture(*args, &block)
  else
    super
  end
end

def render(options = {}, locals = {}, &block)

# => renders app/views/posts/content.html.builder
<%= render template: "posts/content", handlers: [:builder] %>
<% # app/views/posts/show.html.erb %>

: Render a template for a different handler.
`:handlers`

# => renders app/views/posts/content.html+tablet.erb
<%= render template: "posts/content", variants: [:tablet] %>
<% # app/views/posts/show.html.erb %>

: Render a template for a different variant.
`:variants`

# => renders app/views/posts/content.text.erb
<%= render template: "posts/content", formats: [:text] %>
<% # app/views/posts/show.html.erb %>

: Override the current format to render a template for a different format.
`:formats`

# => renders "

Hello, World!

"
<%= render inline: "

Hello, <%= name %>!

", locals: { name: "World" } %>

: Hash of local variable assignments for the template.
`:locals`

#### Options


# => renders "

Hello, World

"
<%= render renderable: Greeting.new %>

default.
renderable if it responds to `format`, falling back to `:html` by
context. The format is determined by calling `format` on the
: Renders the provided object by calling `render_in` with the current view
`:renderable`

# => renders "<h1>Hello, World!</h1>"
<%= render html: "

Hello, World!

" %>

# => renders "

Hello, World!

"
<%= render html: "

Hello, World!

".html_safe %>

the string before rendering.
`:html`. If the string is not `html_safe?`, performs HTML escaping on
: Renders the provided HTML string, and sets the format as
`:html`

# => renders "Hello, World!"
<%= render plain: "Hello, World!" %>

: Renders the provided text, and sets the format as `:text`.
`:plain`

# => renders "Hello, World!"
<%= render body: "Hello, World!" %>

: Renders the provided text, and sets the format as `:text`.
`:body`

# => renders "

Hello, World!

"
<%= render inline: "

Hello, <%= name %>!

" %>
<% name = "World" %>

: Renders an ERB template string.
`:inline`

# => renders /path/to/some/file
<%= render file: "/path/to/some/file" %>

unsanitized user input.
: Renders the contents of a file. This option should **not** be used with
`:file`

# => renders app/views/posts/_form.html.erb
<%= render partial: "form", locals: { post: Post.new } %>

: See ActionView::PartialRenderer for details.
`:partial`

Pass the rendering mode as first argument to override it.

#### Rendering Mode

# => "

Hello, World

"
<%= render Greeting.new %>

end
end
:html
def format

end
view_context.render html: "

Hello, World

"
def render_in(view_context)
class Greeting

by calling `render_in` with the current view context.
If the first argument responds to `render_in`, the template will be rendered

# => renders app/views/posts/_form.html.erb
<%= render "form", post: Post.new %>
<% # app/views/posts/new.html.erb %>

variable assignments for the template.
Without the rendering mode, the second argument can be a Hash of local

# => renders app/views/comments/_form.html.erb
<%= render "comments/form" %>
<% # app/views/posts/show.html.erb %>

Use the complete view path to render a partial from another directory.

# => renders app/views/posts/_form.html.erb
<%= render "form" %>
<% # app/views/posts/new.html.erb %>

template in the directory of the calling template first.
prefixed with an underscore. The partial renderer looks for the partial
syntax for partial rendering, so the template filename should be
Pass the template to render as the first argument. This is shorthand

Renders a template and returns the result.
def render(options = {}, locals = {}, &block)
  case options
  when Hash
    in_rendering_context(options) do |renderer|
      if block_given?
        view_renderer.render_partial(self, options.merge(partial: options[:layout]), &block)
      else
        view_renderer.render(self, options)
      end
    end
  else
    if options.respond_to?(:render_in)
      options.render_in(self, &block)
    else
      view_renderer.render_partial(self, partial: options, locals: locals, &block)
    end
  end
end