This project is archived and is in readonly mode.
Parts of template are rendered twice, induced by yield or cache
-
Piotr Sarnacki
- Importance changed from to Low
You need to use capture in your helper:
def foo(&block) capture(&block) endAnd add = in front of the call in view:
<%= foo do -%> Something <% end -%>As of second example, I think that this is based on implementation of <%= block_helper do %> in Rails 3:
https://github.com/rails/rails/blob/master/actionpack/lib/action_vi...I don't know if this can be fixed, as for now you should use that form:
<%- if false -%> <%= cache do -%> Something <%- end -%> <%- else -%> foobar <%- end -%> -
Jan
Well, the cache thing was my real problem, the other one was just how I tried to understand what might be going wrong. So thanks for pointing out my mistakes! I already went a little crazy.
-
Jan
API and guide use <% cache do %> without =.
http://api.rubyonrails.org/classes/ActionView/Helpers/CacheHelper.h...
http://guides.rubyonrails.org/caching_with_rails.html#fragment-caching -
Piotr Sarnacki
- State changed from new to invalid
I think that cache works both with = and without, probably it just writes to @output_buffer and returns nil, so = does not change anything. I just thought that it needs it. Seems like a little bit inconsistent, though.
I think this can be closed and I'll start a discussion on block helpers on rails group later.