Ruby on Rails includes the concept of layouts, which enable you to specify that outer framework that pages in your application will be rendered within. Most view libraries support includes, which enable you to do things like this:
Do stuff here.
Layouts are a bit nicer in that you don’t even have to maintain the includes on each page. One nice feature of layouts is that if you create a variable within a page, it will be accessible when the enclosing layout is rendered. So you can have a layout like this:
And then a page like this:
<% @page_title = "My Web Page">
<%= @page_title %>
This is my web page.
The page title variable that’s set on the page will be visible to the layout, enabling you to use titles specific to each page even though they’re all rendered in the same layout.
In my view, I have the following:
<% @page_specific_scripts_in = "controller_index" %>
And then in
controller_index.js. This works, but I can’t help but wonder if there’s a better way.