(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 have it working, but my solution ugly so I believe I''m not doing it the proper Rails way. 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" As it is, I have a loop in the controller that checks for the existance of a parameter for each language_id, but that feels ugly, so I''m sure I must be doing something wrong, but what I don''t know. Any help is appreciated. Thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
-----Original Message----- From: rubyonrails-talk@googlegroups.com [mailto:rubyonrails-talk@googlegroups.com]On Behalf Of François Montel Sent: Monday, September 11, 2006 11:36 AM To: rubyonrails-talk@googlegroups.com Subject: [Rails] Collection_select and Ajax. (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 have it working, but my solution ugly so I believe I'm not doing it the proper Rails way. 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> %> ... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ Francois, I believe you just need to change you collection selection to... <%= collection_select (:item, :language_id, @languages, :id, :lang %> (That assumes that the fields within @languages are id and lang) You can then reference the values returned as "params[:item][:language_id]" in a normal controller. However, with AJAX the value returned is kept in the "request.raw_post" variable, so you will probably have to check that to get the returned value. HTH, Nathan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Nathan Leach wrote:> with AJAX the value returned is kept in the "request.raw_post" variable, so you will probably have to check that to get the returned value.That''s what I was missing. I didn''t know about request.raw_post and couldn''t figure out where Ajax was storing the value. Tx! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---