开发者

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 la开发者_StackOverflow中文版yout 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!


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜