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

content_for with flush parameter #4226

Merged
merged 1 commit into from Dec 29, 2011

Conversation

Projects
None yet
3 participants
@grentis
Contributor

grentis commented Dec 28, 2011

Hi all,
I have a problem using content_for with nested layouts. I have a template like this one

...
    <h1><%= content_for :box_title %></h1>
    <div class="box_content">
      <%= yield %>
    </div>
...

called for render multiple partials from a view

...
  <%= render partial: 'agents_box', layout: 'layouts/internal/box' %>
  <%= render partial: 'users_box', layout: 'layouts/internal/box' %>
...

_agents_box.html.erb

<% content_for_clear :box_title do %>Server Management<% end %>

_users_box.html.erb

<% content_for_clear :box_title do %>Users<% end %>

Due to the behavior of the content_for function (concatenate) the page is not displayed correctly. (the first h1 contains "Server Management" and the second one "Server ManagementUsers")

In order to solve this kind of problem I updated the content_for method to accept another parameter (flush - false by default) used to decide if the content should be concatenated or replaced.

Using this in my example the page is displayed in the right way

_agents_box.html.erb

<% content_for :box_title, true do %>Server Management<% end %>

_users_box.html.erb

<% content_for :box_title, true do %>Users<% end %>

Hope this can be useful also for other people

@josevalim

This comment has been minimized.

Show comment
Hide comment
@josevalim

josevalim Dec 29, 2011

Contributor

It looks good, but we probably should do something like this: flush = content if block_given? so we don't always need to pass the second parameter as nil when using the block form.

Contributor

josevalim commented Dec 29, 2011

It looks good, but we probably should do something like this: flush = content if block_given? so we don't always need to pass the second parameter as nil when using the block form.

@sikachu

This comment has been minimized.

Show comment
Hide comment
@sikachu

sikachu Dec 29, 2011

Member

Agree with @josevalim. Would you please fix that and force-push to your branch?

Member

sikachu commented Dec 29, 2011

Agree with @josevalim. Would you please fix that and force-push to your branch?

@grentis

This comment has been minimized.

Show comment
Hide comment
@grentis

grentis Dec 29, 2011

Contributor

I made the changes... I hope I have done the right things with the force-push process

Contributor

grentis commented Dec 29, 2011

I made the changes... I hope I have done the right things with the force-push process

josevalim added a commit that referenced this pull request Dec 29, 2011

@josevalim josevalim merged commit 5ac0273 into rails:master Dec 29, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment