This project is archived and is in readonly mode.
content_tag isn't rendering blocks correctly
-
Rohit Arondekar
- Assigned user set to Mikel Lindsaar
Confirmed on Rails master on 1.9.2-head in rails console. Output is in a pastie => http://pastie.org/979318
-
Rohit Arondekar
I've attached a failing test for this issue.
-
Santiago Pastorino
- Milestone cleared.
- Tag changed from rails 3.0, content_tag to rails 3.0, content_tag, patch, test
I'm a bit sleepy but seems that you miss the concat ... test case attached.
-
Rohit Arondekar
Thanks (again) Santiago. Jonathan you have to use concat inside the content_tag block, so your function should be:
def panel(title = ' ', &block)content_tag(:div, :class => "panel") do concat content_tag(:div, title, :class => "header") concat content_tag(:div, capture(&block), :class => "contents contents-non-table") endend
-
Jonathan Hicks
Ok, that's fine but I don't think this example matches the one given
in the video on railsdispatch.com. I believe Yahuda's example was for
a sidebar and didn't accept a block, but it was very similar to my
example. Something like:def sidebar() content_tag(:ul, :class => "sidebar") do content_tag(:li, "Welcome") content_tag(:li, "Home") end end -
Yehuda Katz (wycats)
- State changed from new to invalid
In the outside-ERB form, you need to return a String from the helper, so you would do:
def panel(title = ' ', &block) content_tag(:div, :class => "panel") do content_tag(:div, title, :class => "header") << content_tag(:div, capture(&block), :class => "contents contents-non-table") end end
