Rails: Structured Layout

I wrote the way to build structured layout in Rails.

You can use it when you want to use the same frame according to the page URLs. For example, to show control bar in admin pages.


I examined in the following environment.

  • Rails 3, 4

How to do it?

Usually, app/views/layouts/application.html.erb is the layout file. This time, let’s create app/views/layouts/sub_application.html.haml. In my recent project, I created an layout under another directory, such as app/views/something/layouts/application.html.haml.

According to the Ruby version, you have to write as render :templates =>'layouts/application'.

Here, defining :content. And indicate to show :content in layouts/application.

Like this, the layout template shows show :content if :content is defined, otherwise it shows yield.