Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render a non-partial layout while passing it a block?

When I render a layout while passing it a block, for example:

render(:layout => 'layouts/application') {...}

it requires the layout to be a partial (_application.html.erb). Is it possible to render a regular, non-partial layout without the leading underscore in its name?

Thanks!

like image 378
widgetycrank Avatar asked Nov 15 '22 05:11

widgetycrank


1 Answers

If you pass a block to render, it is rendered as a partial as seen in the snippet below:

if block_given?
      _render_partial(options.merge(:partial => options[:layout]), &block)

The full render method in Rails 3 currently looks as follows:

def render(options = {}, locals = {}, &block)
  case options
  when Hash
    if block_given?
      _render_partial(options.merge(:partial => options[:layout]), &block)
    elsif options.key?(:partial)
      _render_partial(options)
    else
      template = _determine_template(options)
      lookup_context.freeze_formats(template.formats, true)
      _render_template(template, options[:layout], options)
    end
  when :update
    update_page(&block)
  else
    _render_partial(:partial => options, :locals => locals)
  end
end
like image 183
clemensp Avatar answered Feb 15 '23 16:02

clemensp