Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

content_tag_for should behave like content_tag

#871

The attached patch allows content_tag_for to be used in all cases where content_tag should work.

As it stands calling content_tag_for in a helper, with a block ala...


def voodoo_summary(voodoo)
  div_for(voodoo) do
    h(voodoo.name) + " has " +
    pluralise(voodoo.spells.count, "spells") +
    link_to("[more details on #{voodoo.name}]", voodoo)
  end
end

When this is called from the erb template...


<% @spell_book.voodoo.each do |voodoo| %>
  <%= voodoo_summary(voodoo) %>
<% end %>

We end up getting multiple renders and worse.

Attached patch makes content_tag_for use content_tag in a DRYer way... using it's code to prevent this.

Test included for good luck.

Reported by Tom Lea · August 20th, 2008 @ 05:36 PM

State: committed
Milestone: 2.x
Assigned to: Michael Koziarski Michael Koziarski
Importance: none

Activity

  1. Tom Lea
  2. Tom Lea
    Tom Lea

    Posted updated patch, minor faux pas, modifying arguments in-pace is bad.

    August 26th, 2008 @ 11:14 AM

  3. Michael Koziarski
    Michael Koziarski
    • Assigned user set to Michael Koziarski

    Did you really post that updated patch?

    August 29th, 2008 @ 08:43 AM

  4. Tom Lea
    Tom Lea

    Yeah, removed the old one to save confusion...

    added the args.shift.dup.

    August 29th, 2008 @ 11:33 AM

  5. Repository
    Repository
    • State changed from new to committed

    (from [db26b47b9f4dbebd478a5fe6c0dcd38b8697939a]) Ensure that calling content_tag_for in a helper doesn't cause duplicate output.

    Signed-off-by: Michael Koziarski michael@koziarski.com [#871 content_tag_for should behave like content_tag state:committed] http://github.com/rails/rails/co...

    August 29th, 2008 @ 07:53 PM