bug in Ajax methods regarding fixed array parameter format in Rails 1.2.5 (Autocompleter) ?

19 views
Skip to first unread message

Andrew Kaspick

unread,
Oct 14, 2007, 7:34:39 PM10/14/07
to prototy...@googlegroups.com
Hello,

This is an issue that I've come across with the new rails 1.2.5
release, but I'm not sure if the problem lies within Rails, prototype
or scriptaculous. My testing seems to point more towards
scriptaculous, but I'm not sure and maybe somebody can explain this
one.

Looking at the two method calls using an array parameter (field), the
url is the exact same for both below (the urls below are how rails
generates these now with recent patches)...

new Ajax.Autocompleter('test', 'test_auto_complete',
'/test/auto_complete_for_test?field%5B%5D=a&field%5B%5D=b&field%5B%5D=c',
{})

new Ajax.Request('/test/auto_complete_for_test?field%5B%5D=a&field%5B%5D=b&field%5B%5D=c');

You can see there is no difference in the url format above.

Now when the Request method is called, rails receives the parameters
as follows (which is correct)...

Processing TestController#auto_complete_for_test (for 127.0.0.1 at
2007-10-14 18:18:34) [POST]
Parameters: {"action"=>"auto_complete_for_test", "field"=>["a", "b",
"c"], "controller"=>"test"}

And when the Autocompleter method is called, rails receives the
parameters as follows (which is wrong, see that the field param is
broken)...

Processing TestController#auto_complete_for_test (for 127.0.0.1 at
2007-10-14 18:21:22) [POST]
Parameters: {"action"=>"auto_complete_for_test", "field"=>["a"],
"controller"=>"test", "amp;field"=>["b", "c"], "test"=>"test"}

To test, I put a js alert in Ajax.Request to display the url (which
the Autocompleter calls as well) and when using Ajax.Request the url
looks like this (& removed)...

'/test/auto_complete_for_test?field%5B%5D=a&field%5B%5D=b&field%5B%5D=c'

but when called via Autocompleter, it looks like this (& not removed)...

'/test/auto_complete_for_test?field%5B%5D=a&field%5B%5D=b&field%5B%5D=c'

Looking at Autocompleter code, I see no url translation or escaping,
just a simple assignment for use with Ajax.Rqeuest, so what's going on
here? I can see why rails would receive the wrong data between the
two, but why does the same url produce different results. I'm totally
confused on this one. Again, this looks like a javascript issue from
either prototype or scriptaculous, but this issue didn't seem to
appear until the latest Rails was released.

Thanks,
Andrew

Andrew Kaspick

unread,
Oct 15, 2007, 1:14:32 AM10/15/07
to prototy...@googlegroups.com
To follow up to my own post, the issue seems to simply be that when
the url resides within a <script> tag, the &amp; remains, but if the
url resides in a js method on a html element, the &amp; is correctly
replaced with a single &.

So this looks to be an issue with the new formatting in rails using
the & for array parameters and I'll now redirect my question to the
rails forum.

Thanks

Reply all
Reply to author
Forward
0 new messages