Forum: Ruby on Rails Ajax, tables and parameters - problem

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.
429e9d8e16b3c6e4ab0c954893e0334a?d=identicon&s=25 mithill (Guest)
on 2005-11-14 00:26
(Received via mailing list)
This problem is very strange. I've included a very simple controller and
a very simple view that you can drop into any rails environment to test
this problem out.

When I submit a form, and the form is inside a table (say a row in a
table) then the parameters sent on the form submission are different
than if the form is not in a table.

When I run a simple test and I submit a form created with a
"form_remote_tag" method and this form is inside a table,
@params.inspect gives the following:

{"action"=>"ajax_submit", "controller"=>"ajax_problem"}

Most notable here is that there are no parameters from the form sent in.
The exact same form created outside of a table generates the following:

{"commit"=>"Submit (no table)", "action"=>"ajax_submit",
"some_param"=>"a value I typed in", "controller"=>"ajax_problem",
"_"=>""}

Vastly different results. The exact controller and view that I used to
obtain these results are included below. Just cut-and-paste the
controller into app/controllers/ajax_problem_controller.rb and put the
view in app/views/ajax_problem/index.rhtml, then test it out. If anyone
can explain to me what I'm doing wrong and how to fix it, it would be
most appreciated.

******** Sample code ************************
** Here is a very simple controller:

class AjaxProblemController < ApplicationController
   layout nil

   def index
   end

   def ajax_submit
     render_text @params.inspect
   end
end

** Here is a very simple view to show the problem:

<html>
   <head>
     <title>Ajax Problem</title>
     <%= javascript_include_tag "prototype" %>
   </head>
   <body>
     <div id="to_update">
     </div>
     <table>
       <tr>
         <%= form_remote_tag(:update => "to_update",
                            :url => { :action => :ajax_submit }
                            ) %>
           <td>
             <%= text_field_tag 'some_param' %>
           </td>
           <td>
             <%= submit_tag "Submit (with a table)" %>
           </td>
         <%= end_form_tag %>
       </tr>
     </table>

     Now outside of a table <br/>
     <br/>
     <%= form_remote_tag(:update => "to_update",
                        :url => { :action => :ajax_submit }
                        ) %>
         <%= text_field_tag 'some_param' %>
         <%= submit_tag "Submit (no table)" %>
     <%= end_form_tag %>
   </body>
</html>
429e9d8e16b3c6e4ab0c954893e0334a?d=identicon&s=25 mithill (Guest)
on 2005-11-14 01:14
(Received via mailing list)
For got to include:
Rails 0.14.3
Ruby 1.8.2
Gentoo
5565e460a42fbe5669b458b2753f8d34?d=identicon&s=25 codeslush (Guest)
on 2005-11-14 01:29
(Received via mailing list)
Matt,

I just did the test, with your exact code and got proper results.

{"commit"=>"Submit (with a table)", "action"=>"ajax_submit",
"some_param"=>"Michael", "controller"=>"ajax_problem", "_"=>""}

{"commit"=>"Submit (no table)", "action"=>"ajax_submit",
"some_param"=>"Michael", "controller"=>"ajax_problem", "_"=>""}

This is from IE 6.0.  Looks like it may be a versioning issue
somewhere...I just wanted to let you know that the code is proper - at
least from my config.

Regards,

Michael


Matthew Thill <mithill@telusplanet.net> wrote:
For got to include:
Rails 0.14.3
Ruby 1.8.2
Gentoo

Matthew Thill wrote:
> @params.inspect gives the following:
> obtain these results are included below. Just cut-and-paste the
>
>
>
>
>
>
>
>
>

>
>
>
>
>
> Now outside of a table

>
531eb73f8fbf05a197721d02b4e6aadb?d=identicon&s=25 bogdan.ionescu (Guest)
on 2005-11-14 01:35
(Received via mailing list)
Form inside Table is not valid HTML.
The Ajax call is based on some javascript code collecting the values of
the
parameters.
When the form is inside the table, that code is unable to find any
children
of the form. (most likely because you placed those parameters like
<td><%=text_field 'obj','param' %></td>)
So instead of:
<table>
<form>
<tr><td><input></td></tr>
</form>
</table>
use
<form>
<table>
<tr><td><input></td></tr>
</table>
</form>
and it would work fine

Bogdan
429e9d8e16b3c6e4ab0c954893e0334a?d=identicon&s=25 mithill (Guest)
on 2005-11-14 05:45
(Received via mailing list)
That's good to know, thank you. I'll try to borrow someone's Windows
machine and test. I was using Firefox 1.0.7. Browser issues? Anyone else
out there able to get the crazy results I was getting?
429e9d8e16b3c6e4ab0c954893e0334a?d=identicon&s=25 mithill (Guest)
on 2005-11-14 06:00
(Received via mailing list)
Thank you, that was it. I would have thought that you could make just
one row of a table into a form (as I did) but I guess this is not valid
html, as you said.

I can now confirm what an earlier poster said, that IE 6 does do what I
expect. IE 6 supporting non-standard html? I'm shocked.
531eb73f8fbf05a197721d02b4e6aadb?d=identicon&s=25 bogdan.ionescu (Guest)
on 2005-11-14 10:26
(Received via mailing list)
IE has always been a pain in the ass for web developers, so I am shocked
that you are shocked ;)
This topic is locked and can not be replied to.