module ActionView::Helpers::CaptureHelper
def content_for(name, content = nil, options = {}, &block)
<% content_for :script, javascript_include_tag(:defaults) %>
Lastly, simple content can be passed as a parameter:
- <%= content_for :navigation %>
Then, in another template or layout, this code would render only the last link:
<% end %>
<% content_for :navigation, flush: true do %>
<%# Add some other content, or use a different template: %>
<% end %>
<% content_for :navigation do %>
If the flush parameter is +true+ content_for replaces the blocks it is given. For example:
- <%= content_for :navigation %>
Then, in another template or layout, this code would render both links in order:
<% end %>
<% content_for :navigation do %>
And in another place:
<% end %>
<% content_for :navigation do %>
identifier in order. For example:
Note that content_for concatenates (default) the blocks it is given for a particular
this technique is useful if you'll only be using these scripts in a few views.
That will place +script+ tags for your default set of JavaScript files on the page;
<% end %>
<%= javascript_include_tag :defaults %>
<% content_for :script do %>
<%= link_to 'Logout', action: 'logout', remote: true %>
Then, in another view, you could to do something like this:
<% end %>
<% content_for :script do %>
Please login!
<%# This is our view %>
creates the script identifier.
And now, we'll create a view that has a content_for call that