# Some help for form builder?

**URL:** <https://www.ruby-forum.com/t/some-help-for-form-builder/90804>\
**Category:** Rails\
**Created:** [April 1, 2007, 10:27pm UTC](https://www.ruby-forum.com/t/some-help-for-form-builder/90804 "2007-04-01T22:27:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [April 1, 2007, 10:27pm UTC](https://www.ruby-forum.com/t/some-help-for-form-builder/90804/1 "2007-04-01T22:27:30Z")

</div>

Hi all

I’d like to group my fields on a form into visual separate areas. My  
plan is to surround fields that belong together with fieldset/legend  
tags:

 Personal Information form.text\_field :name form.text\_field :email Additional Information form.text\_field :xxx form.text\_field :yyy

I’d like to add a helper method to the form builder that creates this  
fieldset/legend tag pair:

\<% form.visual\_group(‘Personal Information’).do %\>  
form.text\_field :name  
form.text\_field :email  
\<% end %\>

\<% form.visual\_group(‘Additional Information’).do %\>  
form.text\_field :xxx  
form.text\_field :yyy  
\<% end %\>

I’ve come so far with my poor Ruby knowledge:

def bla(caption)  
“#{caption}#{yield}”  
end

Sadly this does not really work - the fieldset/legend tags are not  
written to the template…

How can I achieve this behavior? 🙂 Thanks  
Josh

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [April 2, 2007, 10:51am UTC](https://www.ruby-forum.com/t/some-help-for-form-builder/90804/2 "2007-04-02T10:51:30Z")

</div>

Joshua M. wrote:

> …  
> I’ve come so far with my poor Ruby knowledge:
> 
> def bla(caption)  
> “#{caption}#{yield}”  
> end
> 
> Sadly this does not really work - the fieldset/legend tags are not  
> written to the template…
> 
> How can I achieve this behavior? 🙂 Thanks  
> Josh

I haven’t time to check what you misses, but for obtaining the same  
result, I use the following helper method:

def fieldset\_tag(legend, options = {}, &block)  
concat(content\_tag(‘fieldset’, content\_tag(‘legend’,legend) +  
capture(&block), options), block.binding)  
end

Regards  
Massimo  
[http://www.addsw.it](http://www.addsw.it)

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [April 2, 2007, 6:16pm UTC](https://www.ruby-forum.com/t/some-help-for-form-builder/90804/3 "2007-04-02T18:16:47Z")

</div>

Thank you, but I get the following error:

undefined method `capture’ for #IncenseFormBuilder:0x2368898

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [April 3, 2007, 2:37pm UTC](https://www.ruby-forum.com/t/some-help-for-form-builder/90804/4 "2007-04-03T14:37:58Z")

</div>

Thanks a lot for your help. 🙂

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [April 3, 2007, 10:05am UTC](https://www.ruby-forum.com/t/some-help-for-form-builder/90804/5 "2007-04-03T10:05:19Z")

</div>

Joshua M. wrote:

> Thank you, but I get the following error:
> 
> undefined method `capture’ for #IncenseFormBuilder:0x2368898

The method was intented to be used as

\<% fieldset\_tag(‘Personal Information’) do %\>  
\<%= form.text\_field :name %\>  
\<%= form.text\_field :email %\>  
\<% end %\>

You can put code in app/helpers/application\_helper.rb

If you, instead, want to include it into your formbuilder, then, try to  
include all modules needed (like include  
ActionView::Helpers::CaptureHelper, for capture method; see API)
