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:
<fieldset>
<legend>Personal Information</legend>
form.text_field :name
form.text_field :email
</fieldset>
<fieldset>
<legend>Additional Information</legend>
form.text_field :xxx
form.text_field :yyy
</fieldset>
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)
"<fieldset><legend>#{caption}</legend>#{yield}</fieldset>"
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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Joshua Muheim wrote:> .... > I''ve come so far with my poor Ruby knowledge: > > def bla(caption) > "<fieldset><legend>#{caption}</legend>#{yield}</fieldset>" > end > > Sadly this does not really work - the fieldset/legend tags are not > written to the template... > > How can I achieve this behavior? :-) Thanks > JoshI 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you, but I get the following error: undefined method `capture'' for #<IncenseFormBuilder:0x2368898> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Joshua Muheim 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) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks a lot for your help. :-) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---