Some help for form builder?

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? :slight_smile: Thanks
Josh

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? :slight_smile: 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

Thank you, but I get the following error:

undefined method `capture’ for #IncenseFormBuilder:0x2368898

Thanks a lot for your help. :slight_smile:

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)