# Form\_for with divs and fieldsets =\> stupid

**URL:** <https://www.ruby-forum.com/t/form-for-with-divs-and-fieldsets-stupid/106064>\
**Category:** Rails\
**Created:** [June 6, 2007, 2:53am UTC](https://www.ruby-forum.com/t/form-for-with-divs-and-fieldsets-stupid/106064 "2007-06-06T02:53:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![thekernel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47774/32.png) [@thekernel](https://www.ruby-forum.com/u/thekernel)\
**Post date:** [June 6, 2007, 2:53am UTC](https://www.ruby-forum.com/t/form-for-with-divs-and-fieldsets-stupid/106064/1 "2007-06-06T02:53:37Z")

</div>

If I do this:

+============================================+

 \<% form\_for :item, :url =\> { :controller =\> 'inventory', :action =\> 'create' } do |f| %\> \<%= render :partial =\> 'item\_form', :locals =\> { :f =\> f } %\> \<%= submit\_tag "Add" %\> \<% end %\> 
+============================================+

I get:

+============================================+

Item Qty Year

+============================================+

I don’t get why the form shows up outside the div and fieldset. If I  
move them inside the form\_for block everything works as expected.  
This behavior seems really strange. Is there are reason why it is  
this way, or is this a bug?

## – Amos K. A. King Software Development and Consulting, L.C. [http://dirtyInformation.com](http://dirtyInformation.com)

Looking for something to do? Visit [http://ImThere.com](http://ImThere.com)

---

<div class="post-metadata">

**Author:** ![thekernel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47774/32.png) [@thekernel](https://www.ruby-forum.com/u/thekernel)\
**Post date:** [June 6, 2007, 5:15am UTC](https://www.ruby-forum.com/t/form-for-with-divs-and-fieldsets-stupid/106064/2 "2007-06-06T05:15:56Z")

</div>

Something’s going wrong because the form tag is not being generated at  
all. I’m surprised there’s not an error though. The only thing pops  
out at me is the fact that you aren’t passing an object to it.  
Typically form\_for is called like:

form\_for :item, @item, :url =\> …

Where :item is the name, and @item provides the values for form  
persistence.

On 6/5/07, Amos K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> <% end %>
> 
> ```
> 
> move them inside the form\_for block everything works as expected. \>

–  
Gabe da Silveira  
[http://darwinweb.net](http://darwinweb.net)

---

<div class="post-metadata">

**Author:** ![thekernel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47774/32.png) [@thekernel](https://www.ruby-forum.com/u/thekernel)\
**Post date:** [June 6, 2007, 5:39am UTC](https://www.ruby-forum.com/t/form-for-with-divs-and-fieldsets-stupid/106064/3 "2007-06-06T05:39:58Z")

</div>

I don’t claim to know why this is happening, but what happens when  
you move the form\_for into the partial?

Also, shouldn’t you have fieldset inside your form\_for?

 \<%= render :partial =\> 'item\_form', :locals =\> { :f =\> f } %\> 

* * *

\_item\_form.rhtml

```
 <% form_for :item, :url => { :controller => 'inventory', :action

```

=\> ‘create’ } do |f| %\>

```
   <%= submit_tag "Add" %>
 <% end %>

```

–  
James M.

---

<div class="post-metadata">

**Author:** ![thekernel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47774/32.png) [@thekernel](https://www.ruby-forum.com/u/thekernel)\
**Post date:** [June 6, 2007, 4:45pm UTC](https://www.ruby-forum.com/t/form-for-with-divs-and-fieldsets-stupid/106064/4 "2007-06-06T16:45:43Z")

</div>

I moved the div and the fieldset inside the form\_for and it works. I  
just don’t know why when I put the tags outside it doesn’t get  
generated in the right place. I just want to know if there is a  
reason for this behavior. I also don’t know why a form tag wasn’t  
created. I never tried to submit anything when the form was  
displaying outside the fieldset.

Gabe: You only need to pass an object in if the form is going to be  
pre-populated. At least that is my understanding.

There is some refactoring being done. The divs and fieldsets and  
form\_fors are being moved to the partial.

On Jun 5, 10:39 pm, James M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![thekernel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47774/32.png) [@thekernel](https://www.ruby-forum.com/u/thekernel)\
**Post date:** [June 6, 2007, 9:23pm UTC](https://www.ruby-forum.com/t/form-for-with-divs-and-fieldsets-stupid/106064/5 "2007-06-06T21:23:35Z")

</div>

Wait, if you move the div and fieldset inside the form\_for the form  
tags are being generated correctly? Or just the order comes out  
correct? The latter makes perfect sense, but the former would be  
exceedingly strange.

On Jun 6, 8:44 am, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![thekernel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47774/32.png) [@thekernel](https://www.ruby-forum.com/u/thekernel)\
**Post date:** [June 6, 2007, 9:32pm UTC](https://www.ruby-forum.com/t/form-for-with-divs-and-fieldsets-stupid/106064/6 "2007-06-06T21:32:35Z")

</div>

If I put the div and fieldset inside the form\_for everything is  
correct. The form fields are inside the fieldset which in turn is  
inside the div, and everything forks great. If I place it as about  
everything shows up out of order. I’m using Rails 1.2.3 and Ruby  
1.8.6.

On 6/6/07, dasil003 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > generated in the right place. I just want to know if there is a  
> > On Jun 5, 10:39 pm, James M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> > 
> > > 
> > 
> > > > ```
> > > > <%form_for:item, :url => { :controller => 'inventory', :action
> > > > 
> > > > ```
> > > > 
> > > > ## +============================================+ type=“text”\> +============================================+
> > > > 
> > > > Looking for something to do? Visithttp://ImThere.com
> 
> >

## – Amos K. A. King Software Development and Consulting, L.C. [http://dirtyInformation.com](http://dirtyInformation.com)

Looking for something to do? Visit [http://ImThere.com](http://ImThere.com)
