Skip to content

Instantly share code, notes, and snippets.

@mattbrictson
Last active October 5, 2025 17:02
Show Gist options
  • Save mattbrictson/9240548 to your computer and use it in GitHub Desktop.
Save mattbrictson/9240548 to your computer and use it in GitHub Desktop.

Revisions

  1. mattbrictson revised this gist Jun 27, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion layouts_helper.rb
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ module LayoutsHelper
    #
    def parent_layout(layout)
    @view_flow.set(:layout, output_buffer)
    output = render(:file => "layouts/#{layout}")
    output = render(template: "layouts/#{layout}")
    self.output_buffer = ActionView::OutputBuffer.new(output)
    end
    end
  2. mattbrictson created this gist Feb 26, 2014.
    14 changes: 14 additions & 0 deletions application.html.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    <%= render("shared/navbar") %>

    <div class="container">

    <%= render("shared/alerts") %>
    <%= render("shared/page_header") %>

    <%= yield %>

    <%= render("shared/footer") %>

    </div>

    <% parent_layout "base" %>
    24 changes: 24 additions & 0 deletions base.html.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    <!DOCTYPE html>
    <html>
    <head>
    <%= stylesheet_link_tag("application", "data-turbolinks-track" => true) %>
    <%= javascript_include_tag("application", "data-turbolinks-track" => true) %>

    <%= yield(:head) %>

    <meta charset="utf8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <%= csrf_meta_tags %>

    <title>
    <%= yield(:title) + " – " if content_for?(:title) %>
    RailsStarter
    </title>
    </head>
    <body>

    <%= yield %>

    </body>
    </html>
    17 changes: 17 additions & 0 deletions layouts_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    module LayoutsHelper
    # Used to achieve nested layouts without content_for. This helper relies on
    # Rails internals, so beware that it make break with future major versions
    # of Rails. Inspired by http://stackoverflow.com/a/18214036
    #
    # Usage: For example, suppose "child" layout extends "parent" layout.
    # Use <%= yield %> as you would with non-nested layouts, as usual. Then on
    # the very last line of layouts/child.html.erb, include this:
    #
    # <% parent_layout "parent" %>
    #
    def parent_layout(layout)
    @view_flow.set(:layout, output_buffer)
    output = render(:file => "layouts/#{layout}")
    self.output_buffer = ActionView::OutputBuffer.new(output)
    end
    end