# Form doesn't appear in the view.. why?

**URL:** <https://www.ruby-forum.com/t/form-doesnt-appear-in-the-view-why/158040>\
**Category:** Rails\
**Created:** [January 18, 2009, 11:38am UTC](https://www.ruby-forum.com/t/form-doesnt-appear-in-the-view-why/158040 "2009-01-18T11:38:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gte351s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5f9b8f/32.png) [@gte351s](https://www.ruby-forum.com/u/gte351s)\
**Post date:** [January 18, 2009, 11:38am UTC](https://www.ruby-forum.com/t/form-doesnt-appear-in-the-view-why/158040/1 "2009-01-18T11:38:54Z")

</div>

Hi - I have a strange thing happening in my app. I’m trying to replace a  
table row with a form row using link\_to\_remote and form\_for. In my index  
view I have a call to edit:

\<%= link\_to\_remote ‘edit vendor’, :url =\> { :action =\> ‘edit\_vendor’ }  
%\>

This works on a partial (\_vendor.html.erb):

\<% @vendor = vendor %\>

 \<% unless edit\_mode -%\> \<%= h vendor.name %\> \<%= h vendor.location %\> \<% else -%\> \<% form\_for :vendor do |f| -%\> \<%= f.text\_field :name, :size =\> 15 %\> \<%= f.text\_field :location, :size =\> 15 %\> \<%= f.submit 'save' %\> \<% end -%\> \<% end -%\>

and finally I have a js template that adds the edit row and removes the  
original one  
(edit\_vendor.js.rjs):

page.insert\_html :after, ‘vendor\_3’,  
:partial =\> ‘vendor’,  
:object =\> Vendor.find(3), :locals =\> { :edit\_mode =\>  
true }

page.remove ‘vendor\_3’

I just tried testing with vendor\_3 to see if this works. The action  
generates the form in the page source, but it isn’t visible on the  
actual page. I can see the form tag using firebug (it appears faded, as  
though display:none – when it’s not), but for some reason which eludes  
me, it’s invisible in the browser:

I checked and it doesn’t have any other visibility css rules and such…  
Any clues what’s happening?

---

<div class="post-metadata">

**Author:** ![gte351s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5f9b8f/32.png) [@gte351s](https://www.ruby-forum.com/u/gte351s)\
**Post date:** [January 18, 2009, 1:05pm UTC](https://www.ruby-forum.com/t/form-doesnt-appear-in-the-view-why/158040/2 "2009-01-18T13:05:33Z")

</div>

Shilo A. wrote:

> ```
> <% form_for :vendor do |f| -%>
> <td><%= f.text_field :name, :size => 15 %></td>
> <td><%= f.text_field :location, :size => 15 %></td>
> 
> ```

Don’t forms automatically have ‘display: block;’ style? Meaning you  
can’t nest  
them between

| blocks?

I think this error is similar to a mismatched

 | situation, where the  
browser  
just throws away the incorrect cell… |

---

<div class="post-metadata">

**Author:** ![gte351s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5f9b8f/32.png) [@gte351s](https://www.ruby-forum.com/u/gte351s)\
**Post date:** [January 18, 2009, 1:56pm UTC](https://www.ruby-forum.com/t/form-doesnt-appear-in-the-view-why/158040/3 "2009-01-18T13:56:42Z")

</div>

On 18 Jan 2009, at 12:04, Phlip wrote:

> 

IIRC tr elements can only contain td elements. You can’t put a form  
there.

Fred

---

<div class="post-metadata">

**Author:** ![gte351s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5f9b8f/32.png) [@gte351s](https://www.ruby-forum.com/u/gte351s)\
**Post date:** [January 18, 2009, 3:39pm UTC](https://www.ruby-forum.com/t/form-doesnt-appear-in-the-view-why/158040/4 "2009-01-18T15:39:49Z")

</div>

Try this

 \<% form\_for :vendor do |f| -%\> \<%= f.text\_field :name, :size =\> 15 %\> \<%= f.text\_field :location, :size =\> 15 %\> \<%= f.submit 'save' %\> \<% end -%\> 

On Jan 18, 5:39 am, Shilo A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![gte351s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5f9b8f/32.png) [@gte351s](https://www.ruby-forum.com/u/gte351s)\
**Post date:** [January 18, 2009, 2:39pm UTC](https://www.ruby-forum.com/t/form-doesnt-appear-in-the-view-why/158040/5 "2009-01-18T14:39:25Z")

</div>

Frederick C. wrote:

> On 18 Jan 2009, at 12:04, Phlip wrote:
> 
> > 
> 
> IIRC tr elements can only contain td elements. You can’t put a form  
> there.
> 
> Fred

Fred - I suppose you’re right. I tried changing this:

 \<% form\_for :vendor do |f| -%\> \<%= f.text\_field :name, :size =\> 15 %\> \<%= f.text\_field :location, :size =\> 15 %\> \<%= f.submit 'save' %\> \<% end -%\>

to this (simple table row):

 one two three

and it worked… Is there no way to render anything other than \<td/th\>  
tags inside

 ?

---

<div class="post-metadata">

**Author:** ![gte351s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5f9b8f/32.png) [@gte351s](https://www.ruby-forum.com/u/gte351s)\
**Post date:** [January 19, 2009, 4:33pm UTC](https://www.ruby-forum.com/t/form-doesnt-appear-in-the-view-why/158040/6 "2009-01-19T16:33:31Z")

</div>

I don’t believe that form is valid between table and tr either.

2009/1/19 klochner [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![gte351s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5f9b8f/32.png) [@gte351s](https://www.ruby-forum.com/u/gte351s)\
**Post date:** [January 19, 2009, 11:56am UTC](https://www.ruby-forum.com/t/form-doesnt-appear-in-the-view-why/158040/7 "2009-01-19T11:56:50Z")

</div>

or the following should work, although I’d consider just writing a  
different  
partial (\_edit\_vendor) to render the \<% else %\> block, and I’d also  
just duplicate the closing in each block, trading an extra  
line of code for a self-contained table row.

\<% unless edit\_mode -%\>

 \<%= h vendor.name %\> \<%= h vendor.location %\>

\<% else -%\>  
\<% form\_for :vendor do |f| -%\>  
  
\<%= f.text\_field :name, :size =\> 15 %\>  
\<%= f.text\_field :location, :size =\> 15 %\>  
\<%= f.submit ‘save’ %\>  
\<% end -%\>  
\<% end -%\>

On Jan 18, 5:38 am, Shilo A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
