v1.0.0 -
Show latest stable
-
0 notes
- 1.0.0 (0)
- 1.1.6 (-4)
- 1.2.6 (0)
- 2.0.3 (-38)
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (-1)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (0)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (4)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (7)
- 7.1.3.4 (0)
- 7.2.3 (0)
- 8.0.0 (0)
- 8.1.1 (0)
- What's this?
Capture lets you extract parts of code into instance variables which can be used in other points of the template or even layout file.
Capturing a block into an instance variable
<% @script = capture do %> [some html...] <% end %>
Add javascript to header using content_for
content_for("name") is a wrapper for capture which will store the fragment in a instance variable similar to @content_for_layout.
layout.rhtml:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>layout with js</title> <script type="text/javascript"> <%= @content_for_script %> </script> </head> <body> <%= @content_for_layout %> </body> </html>
view.rhtml
This page shows an alert box! <% content_for("script") do %> alert('hello world') <% end %> Normal view text

