-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of François Montel
Sent: Monday, September 11, 2006 11:36 AM
To: [email protected]
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’,
%>
…
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~–~—