Forum: Ruby on Rails Form doesn't appear in the view.. why?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
006a4831843b48f6102d5d3cf92ae283?d=identicon&s=25 Shilo Ayalon (gte351s)
on 2009-01-18 11:38
Attachment: invisible.png (50 KB)
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 %>
<tr id="vendor_<%= vendor.id %>">
  <% unless edit_mode -%>
    <td><%= h vendor.name %></td>
    <td><%= h vendor.location %></td>
  <% else -%>
    <% form_for :vendor do |f| -%>
      <td><%= f.text_field :name, :size => 15 %></td>
      <td><%= f.text_field :location, :size => 15 %></td>
      <td><%= f.submit 'save' %></td>
    <% end -%>
  <% end -%>
</tr>

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:

<tr id="vendor_3">
  <form method="post" action="/vendors/edit_vendor">
    <div style="margin: 0pt; padding: 0pt;"/>
    <input type="hidden"
value="248d3190ffb7dc764601dce231cd669054914fc5"
           name="authenticity_token"/>
    <td><input type="text" value="Vendor 1" size="15"
name="vendor[name]"
               id="vendor_name"/></td>
    <td><input type="text" value="New York" size="15"
name="vendor[location]"
               id="vendor_location"/></td>
    <td><input type="submit" value="save" name="commit"
id="vendor_submit"/></td>
  </form>
</tr>

I checked and it doesn't have any other visibility css rules and such...
Any clues what's happening?
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-01-18 13:05
(Received via mailing list)
Shilo Ayalon 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 <table><tr><td> blocks?

I think this error is similar to a mismatched <td> situation, where the
browser
just throws away the incorrect cell...
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-01-18 13:56
(Received via mailing list)
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
006a4831843b48f6102d5d3cf92ae283?d=identicon&s=25 Shilo Ayalon (gte351s)
on 2009-01-18 14:39
Frederick Cheung 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:

<tr>
  <% form_for :vendor do |f| -%>
    <td><%= f.text_field :name, :size => 15 %></td>
    <td><%= f.text_field :location, :size => 15 %></td>
    <td><%= f.submit 'save' %></td>
  <% end -%>
</tr>

to this (simple table row):

<tr>
  <td>one</td>
  <td>two</td>
  <td>three</td>
</tr>

and it worked.. Is there no way to render anything other than <td/th>
tags inside <tr> ?
D3fe2dc4435cdd79e58d3e1380a557a1?d=identicon&s=25 Teedub (Guest)
on 2009-01-18 15:39
(Received via mailing list)
Try this

<tr>
  <td colspan="3">
    <% form_for :vendor do |f| -%>
      <%= f.text_field :name, :size => 15 %>
      <%= f.text_field :location, :size => 15 %>
      <%= f.submit 'save' %>
    <% end -%>
  </td>
</tr>

On Jan 18, 5:39 am, Shilo Ayalon <rails-mailing-l...@andreas-s.net>
06d2325506af65508893e873ca193d6a?d=identicon&s=25 klochner (Guest)
on 2009-01-19 11:56
(Received via mailing list)
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 </tr> in each block, trading an extra
line of code for a self-contained table row.

<% unless edit_mode -%>
  <tr id="vendor_<%= vendor.id %>">
    <td><%= h vendor.name %></td>
    <td><%= h vendor.location %></td>

  <% else -%>
    <% form_for :vendor do |f| -%>
    <tr id="vendor_<%= vendor.id %>">
      <td><%= f.text_field :name, :size => 15 %></td>
      <td><%= f.text_field :location, :size => 15 %></td>
      <td><%= f.submit 'save' %></td>
    <% end -%>
  <% end -%>
</tr>





On Jan 18, 5:38 am, Shilo Ayalon <rails-mailing-l...@andreas-s.net>
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-01-19 16:33
(Received via mailing list)
I don't believe that form is valid between table and tr either.

2009/1/19 klochner <klochner@gmail.com>
This topic is locked and can not be replied to.