# Wrapper Helper Help Please

**URL:** <https://www.ruby-forum.com/t/wrapper-helper-help-please/119775>\
**Category:** Rails\
**Created:** [November 10, 2007, 10:59am UTC](https://www.ruby-forum.com/t/wrapper-helper-help-please/119775 "2007-11-10T10:59:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 10, 2007, 10:59am UTC](https://www.ruby-forum.com/t/wrapper-helper-help-please/119775/1 "2007-11-10T10:59:42Z")

</div>

Hi all. I’m hoping this is a simple one that someone can put me right  
on.

I have a view that ‘wraps’ some div’s around a Page Header and Page  
Content, for formatting reasons:

 'Header Here' 

 'Content Here' 

I use this ‘wrapper’ a lot, so I thought I’d put it into a helper,  
thus:

def lhs\_block(title)  
content\_tag(:div,  
content\_tag(:div,  
content\_tag(:div,title,:class=\>‘PageHeader’) +  
content\_tag(:div,yield,:class=\>‘PageContent’),  
:class=\>‘Page’),  
:id=\>‘LHS’)  
end

This works fine in the view when I do this:

\<%= lhs\_block(‘Header Here’) {‘Content Here’} %\>  
Unfortunately, the content is usually more complex that this and multi-  
line (as you can imagine), so when I tried to do it this way:

\<%= lhs\_block(‘Header Here’) do %\>  
Content Here  
\<% end %\>

All hell broke loose:

compile error  
./script/…/config/…/app/views/contacts/index.rhtml:1: parse error,  
unexpected ‘)’  
\_erbout = ‘’; \_erbout.concat(( lhs\_block(list\_filter(‘list\_wrapper’))  
do ).to\_s); \_erbout.concat “\n”

^  
./script/…/config/…/app/views/contacts/index.rhtml:10: parse error,  
unexpected kEND, expecting ‘)’

I thought this was how it was done, but maybe I’m wrong.

If anyone can see anything glaringly obvious that I’ve done wrong,  
then any help would be appreciated. Or maybe another way to DRY this  
code up so that it’s easier to re-use.

Cheers,

Steve A.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 10, 2007, 12:19pm UTC](https://www.ruby-forum.com/t/wrapper-helper-help-please/119775/2 "2007-11-10T12:19:50Z")

</div>

On 10 Nov 2007, at 09:58, Steve A wrote:

> \<% end %\>
> 
> All hell broke loose:

Judging by similar stuff in rails itself,

def lhs\_block(title, &block)  
content = capture(&block)  
concat(  
content\_tag(:div,  
content\_tag(:div,  
content\_tag(:div,title,:class=\>‘PageHeader’) +  
content\_tag(:div,content,:class=\>‘PageContent’),  
:class=\>‘Page’),  
:id=\>‘LHS’), block.binding)  
end

seems to do the trick.

Fred

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 11, 2007, 11:52am UTC](https://www.ruby-forum.com/t/wrapper-helper-help-please/119775/3 "2007-11-11T11:52:31Z")

</div>

I would like to leave a note: It seems like you are misinterpreting  
part of the views, models and helpers concept on rails.  
Please, take this with some salt because I’m kinda new to rails…

You seem to be replacing a lot of div tags that apparently are  
creating the content header and the content of your website.

I would advise keeping those in a layout, maybe your ‘general’ layout  
if it is used in most of your pages. This would be very helpful in  
case you decide to do some changes in the layout, or a new template.

And if this code is not on most of your pages, then maybe you can use  
a partial to help.

I usually use helper methods to create html tags that are not related  
to the template, like, link\_to\_if\_authorized (this is a helper I’ve  
written today), and those div’s seem to be a big part of your  
template.

The point is, avoid creating large blocks of html code outside  
an .rhtml file. This will make the job of putting a layout together a  
lot easier.

IMO, layouts and views are 90% HTML, Helpers are 10% tops (I currently  
have 2 of them on ApplicationHelpers and none has HTML code),  
controllers and models are 0% HTML.

Take this as a light advice, I could have gotten a totally wrong  
picture.

Best regards,

Felipe

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 10, 2007, 2:10pm UTC](https://www.ruby-forum.com/t/wrapper-helper-help-please/119775/4 "2007-11-10T14:10:24Z")

</div>

Thanks Fred, that works a treat (as long as you use \<% instead of \<  
%= ). I was obviously being too simplistic, and will need to take a  
deeper look at why this works when mine didn’t.

Cheers,

Steve A.

On Nov 10, 7:19 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
