Markus Arike
2005-Nov-08 23:25 UTC
form_remote_tag - Mulitple actions based on user selection
I''ve been searching all of the various Rails lists, and this question has come up, but can''t implement any solution so far. I have a form that allows the user to search Amazon. Using Ian MacDonald''s excellent Ruby/Amazon Library, there are different types of searches the user can perform. I use a select menu to change the search type and I can change actions with a simple line of Javascript like so: <form method="post" action="search_artists"> <select onchange="document.forms[0].action = options [selectedIndex].value"> <option value="search_artists" selected>Music</option> <option value="search_books">Books</option> <option value="search_actors">DVD</option> </select> However, I want to use either form_remote_tag or something like this: <%= submit_to_remote("search", "Search", :url => {:controller => "search", :action => "search_artists"}, :html => {:class => ''search''}, :update => :item, :method => ''get'') %>) </form> <div id="item"></div> Both of which work perfectly, as the results which I display with a three different partial templates, are returned without page refresh. However, in doing so, I am forced to hard code the :action of submit_to_remote, thereby, disabling the line of javascript in the select menu. Duh. So after lurking on this list, enjoying the wealth of info contributed by DHH and all the talented programmers. Any ideas. I remember reading on one list about possibly using observe_field to listen for user events, and somehow update the action. Thanks in advance for any help you may offer, because at this point I am stumped. Markus Arike