If you look at the compiled template, any <% %> blocks are compiled to
something like this:

_buf << '<div ...'

Hence if you had the following (silly) ERB:
<% foo do |b| %>
  <li <%= b %> >
<% end %>

the block portion would get compiled to:

_buf << '<li ';
_buf << ( b )
_buf << ' >'

Hence, if you yield to this block, the return value of the yield will be
_buf. _buf contains the portion of the template that has been rendered
so far. And if the yield is the last statement, then the implicit return
value will be _buf.

So far so good. Now you're wondering, hey, the output should not be in
the template unless you're using <%= %>, right? This should be true, but
in the interest of backwards compatibility, Rails 3 has
append_if_string= - this appends the return value of <% %> blocks if the
value is a string (so old form_for's, etc. don't break). _buf is
conveniently a string as well, and gets added to the page.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to