# Should all form elements for a form be in a single div?

**URL:** <https://www.ruby-forum.com/t/should-all-form-elements-for-a-form-be-in-a-single-div/154925>\
**Category:** Rails\
**Created:** [December 5, 2008, 7:27am UTC](https://www.ruby-forum.com/t/should-all-form-elements-for-a-form-be-in-a-single-div/154925 "2008-12-05T07:27:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [December 5, 2008, 7:27am UTC](https://www.ruby-forum.com/t/should-all-form-elements-for-a-form-be-in-a-single-div/154925/1 "2008-12-05T07:27:17Z")

</div>

My layout file is like this…

 #printing the controller name 

 \<%= yield%\> #THIS IS WHERE THE NEW.HTML.ERB IS RENDERED 

 \<%= yield :sidebox\_1%\>#SOME FORM ELEMENT ARE RENDERED IN HERE 

 \<%= yield :sidebox\_2%\>#SOME FORM ELEMENT ARE RENDERED IN HERE 

If you notice, ive mentioned that some form elements are rendered in  
the “sidebox” divs. If instead i yield them in the “content” div  
alongwith the rest of the form, everything works fine.

I figured maybe its because all the fields do not fall between the  
form\_for and end tags. So i tried something like this

/views/projects/new.html.erb  
\<% form\_for @project do |f| %\>  
\<%= f.error\_messages %\>  
\<% content\_for :formfields do%\>  
\<%=render :partial =\> “project”, :locals =\> {:f =\> f}%\>

\<%= f.submit “Save as Draft” %\>

  
\<% end %\>  
\<% end %\>

/views/layouts/application.html.erb

 \<%= yield%\> 

# \<%= controller.controller\_name.capitalize %\>

```
  <div class="content">
    <% flash.each do |key, msg| %>
          <%= content_tag :p, msg, :id => key, :class => 'flash'

```

%\>  
\<% end %\>  
\<%= yield :formfields%\>

  

```
<div class="sidebar">

  <div class="sidebox">
    <%= yield :sidebox1 %>
  </div>

  <div class="sidebox">
    <%= yield :sidebox2 %>
  </div>

  <div class="sidebox">
    <%= yield :sidebox3 %>
  </div>
</div>
<div style="clear:both;"></div>

```

views/projects/\_project.html.erb

…  
…  
\<% content\_for :sidebox1 do%\>  
…  
…  
\<% end %\>  
\<% content\_for :sidebox2 do%\>  
…  
…  
\<% end %\>  
\<% content\_for :sidebox3 do%\>  
…  
…  
\<% end %\># “…” representing form fields.

This way, the form fields are yielded into a div “content” which is  
part of a larger div “wrapper” that yields the rest of the content  
(including the form\_for and end tags) (did this only for testing, do  
not plan to structure my page this way). In any case, that did not  
work either. The “Submit” button did nothing. The form was rendered  
but clicking the Submit button did not submit anything.  
Any suggestions?

---

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [December 5, 2008, 8:01am UTC](https://www.ruby-forum.com/t/should-all-form-elements-for-a-form-be-in-a-single-div/154925/2 "2008-12-05T08:01:15Z")

</div>

On Thu, Dec 4, 2008 at 10:26 PM, Ram [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I figured maybe its because all the fields do not fall between the  
> form\_for and end tags.

No kidding. For all the “magic” in Rails, you still need to create  
valid markup. 🙂

> The “Submit” button did nothing. The form was rendered  
> but clicking the Submit button did not submit anything.  
> Any suggestions?

Sure, validate your page; if you’re still having problems after that,  
check the page for JS problems with FireBug. Or post a URL here.

## HTH,

Hassan S. ------------------------ removed\_email\_address@domain.invalid
