Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty captures not being empty #1

Open
dreyks opened this issue Aug 20, 2015 · 0 comments
Open

empty captures not being empty #1

dreyks opened this issue Aug 20, 2015 · 0 comments

Comments

@dreyks
Copy link

dreyks commented Aug 20, 2015

<% test = capture do %>
  <% [1, 2, 3].each do |v| %>
    <% next if v <= 3 %>
    <%= v %>
  <% end %>
<% end %>

<%= test if test.present? %>

outputs 123 while it is expected to output nothing. This happens because of Cell::Erb#capture returning yielded value if buffer is empty

def capture(*args)
  value = nil
  buffer = with_output_buffer { value = yield(*args) }

  return buffer.to_s if buffer.size > 0
  value # this applies for "Beachparty" string-only statements. <<<< this
end

ActionView::Helpers::CaptureHelper#capture has an additional check on string.is_a?(String) and returns nil if it fails

Temporary workaround is to put <% nil %> as the last line of capture block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant