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

Review, please: Capture block so content won't leak. #8936

Closed
wants to merge 1 commit into from
Closed

Review, please: Capture block so content won't leak. #8936

wants to merge 1 commit into from

Conversation

josemotanet
Copy link
Contributor

Beware: tests are red.

The following pull request fixed
the block being passed to the appropriate helper method. However, the content
being passed into the block is generating repeated markup on the page due to
some weird ERb evaluation.

This commit tries to capture the block's generated output so the page isn't
flooded with markup, but I'm not able to make the tests pass due to a missing
output buffer. Please help me review this behavior.

Example 1 - it leaks markup to the page.

<%= f.collection_radio_buttons :category, Category.all, :id, :name do |b|%>
  <%= b.label { b.radio_button + b.text } %>
<%- end%>

Example 2 - doesn't leak

<%= f.collection_radio_buttons :category, Category.all, :id, :name do |b| b.label { b.radio_button + b.text }; end %>

The [following pull request](#8916) fixed
the block being passed to the appropriate helper method. However, the content
being passed into the block is generating repeated markup on the page due to
some weird ERb evaluation.

This commit tries to capture the block's generated output so the page isn't
flooded with markup, but I'm not able to make the tests pass due to a missing
output buffer. Please help me review this behavior.
@josemotanet
Copy link
Contributor Author

@rafaelfranca can you help me with this?

@josevalim
Copy link
Contributor

This fix seems correct.

@josemotanet
Copy link
Contributor Author

@josevalim Indeed, but it breaks half a dozen tests and I'm not sure how to fix them.

@vimutter
Copy link

Seems like <%= b.label { b.radio_button + b.text } %> is cause of a problem. I think that there problem inside example. If you use builder, you shouldn't use <%=%>, as builder method will not return markup, usually it expected to return self.

Correct usage is

  <%= f.collection_radio_buttons :category, Category.all, :id, :name do |b|%>
    <% b.label { b.radio_button + b.text } %>
  <%- end%>

@josemotanet
Copy link
Contributor Author

That's the short term correct answer, I thought of that too :) Thanks @vimutter

However, form_for captures the passed block and it should be the same in here, imo. Developers shouldn't be confused about whether to use one or another.

@rafaelfranca
Copy link
Member

@josemota yes, agree. Could you add some tests cases (for the raw template method and for the form helper)?

@josemotanet
Copy link
Contributor Author

@rafaelfranca OK. I'll give it a stab and see if I can pull it off.

@josemotanet
Copy link
Contributor Author

So I'm picking on the topic and, as I said, I'm getting 6 failing tests that look exactly the same:

NoMethodError: undefined method `output_buffer=' for #<ActionView::Helpers::Tags::CollectionRadioButtons:0x000000057b5b60>

I'm not understanding the meaning of this, should the helper contain that writer method and it does not? 😧

I feel obligated to make these tests green again before moving on, can anyone point me somewhere so I can take a better look? Thank you.

@rafaelfranca
Copy link
Member

@josemota I updated your commit with tests and the proper fix. Thank you so much

@josemotanet
Copy link
Contributor Author

Thanks @rafaelfranca!

I apologize for not being able to solve the problem that was at hand, I really wanted to grasp the whole situation. Thanks for giving me a hint, I look forward to contributing more.

@rafaelfranca
Copy link
Member

No problem. Thank you for the bug report and the fixes. I applied because I want this fixes ASAP since I'll need to release simple_form 😄

@josemotanet josemotanet deleted the collection-with-block-capture branch January 23, 2013 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants