(I posted this earlier but it doesn''t appear on the group, so
I''m
writing it again, If it appears twice, I apologize.)
I have a drop-down box that allows the user to select a language. I
want to use Ajax to render a filtered list of items based on the
language selected. I don''t want the user to press a Submit button nor
refresh the page, of course.
I''m using the standard collection_select in my view:
<%= collection_select (''item'',
''language_id'', @languages, ''id'',
''lang'',
{}, { :id => ''lang_select'' } ) %>
<%= observe_field( ''lang_select'',
<snip>
%>
This renders as follows:
<select id="lang_select"
name="item[language_id]"><option
value="1">English</option>
<option value="2">Spanish</option>
<option value="3">French</option></select>
<script type="text/javascript">
//<![CDATA[
new Form.Element.Observer(''lang_select'', 1, function(element,
value)
{new Ajax.Updater(''item_list'',
''/items/filter_by_language'',
{asynchronous:true, evalScripts:true,
<snip>
parameters:value})})
//]]>
</script>
The problem is that the following are the params that Ajax is sending
back to my controller when the user selects a different language:
action: filter_by_language
controller: items
"2": ""
As you can see, rather than the selected value (2 in this case) being
attributed to a param, the param itself is named after the value. What
I want it to be is something like this:
"item[language_id]": "2"
or
"lang_select":"2"
I could write a loop in the controller that checks for the existance of
a parameter for each language_id, but that seems very ugly, so I''m sure
I must be doing something wrong, but what I don''t know.
(Of course I could use a submit form and that would work too, but that
would defeat the beauty of ajax.)
Any help is appreciated. Thanks.
--
"Impossible is nothing."
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060910/92236893/attachment-0001.html