aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/capture_helper.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-09-21 03:40:25 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-09-21 03:40:25 +0000
commit415649760226a7987ba1f8d234c1785d0fa333b0 (patch)
tree52bb4ffe58b508cd6a9423ef611a1ccc67627bcf /actionpack/lib/action_view/helpers/capture_helper.rb
parent0d5a7d1d8c921c3f34f52d3e188de11cff0964e9 (diff)
downloadrails-415649760226a7987ba1f8d234c1785d0fa333b0.tar.gz
rails-415649760226a7987ba1f8d234c1785d0fa333b0.tar.bz2
rails-415649760226a7987ba1f8d234c1785d0fa333b0.zip
Fixed CaptureHelper#content_for to work with the optional content parameter instead of just the block #9434 [sandofsky/wildchild]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7522 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/capture_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/capture_helper.rb12
1 files changed, 9 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb
index 9195641747..8a74ed04b2 100644
--- a/actionpack/lib/action_view/helpers/capture_helper.rb
+++ b/actionpack/lib/action_view/helpers/capture_helper.rb
@@ -93,7 +93,7 @@ module ActionView
# That will place <script> tags for Prototype, Scriptaculous, and application.js (if it exists)
# on the page; this technique is useful if you'll only be using these scripts in a few views.
#
- # Also, note that content_for concatenates the blocks it is given for a particular
+ # Note that content_for concatenates the blocks it is given for a particular
# identifier in order. For example:
#
# <% content_for :navigation do %>
@@ -109,7 +109,11 @@ module ActionView
# Then, in another template or layout, this code would render both links in order:
#
# <ul><%= yield :navigation %></ul>
- #
+ #
+ # Lastly, simple content can be passed as a parameter:
+ #
+ # <% content_for :script, javascript_include_tag(:defaults) %>
+ #
# WARNING: content_for is ignored in caches. So you shouldn't use it
# for elements that will be fragment cached.
#
@@ -118,7 +122,9 @@ module ActionView
# would be avaiable as <tt><%= @content_for_footer %></tt>. The preferred usage is now
# <tt><%= yield :footer %></tt>.
def content_for(name, content = nil, &block)
- eval "@content_for_#{name} = (@content_for_#{name} || '') + capture(&block)"
+ existing_content_for = instance_variable_get("@content_for_#{name}").to_s
+ new_content_for = existing_content_for + (block_given? ? capture(&block) : content)
+ instance_variable_set("@content_for_#{name}", new_content_for)
end
private