module ActionView::Helpers::RenderingHelper
def render(options = {}, locals = {}, &block)
<%= 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