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


#1

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?


#2

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…

#3

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


#4

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


#5

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

?

#6

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

2009/1/19 klochner removed_email_address@domain.invalid


#7

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