Forum: Ruby on Rails Help: Multiple Form Actions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
365aa622f1dccc5efa83b041f68ad98b?d=identicon&s=25 marike1 (Guest)
on 2005-11-12 12:50
(Received via mailing list)
I'm having a hard time finding an answer to my question.  I would
like to have multiple form actions based on what the user selects.
For example, I trying to do something similar to Amazon Zuggest,
using Ian McDonald's Ruby/Amazon.

I have three types of searches which translates to 3 actions in the
SearchController.  I have a drop down menu 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>

This works.  The problem is, 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.

Does anyone have any ideas on how to implement this ? Sorry that this
is my second time asking this question on this list.  I know you're
all busy, and I know Ruby, but am fairly new to Rails.  I'd rather
not use three forms for what should be fairly simple.

Thanks in advance,
Regards, Markus Arike

http://www.michaelarike.com
3dd4b52a0946bd698b1d1635a46ea3a3?d=identicon&s=25 francois.beausoleil (Guest)
on 2005-11-12 12:50
(Received via mailing list)
Hello Markus !

2005/11/11, Markus Arike <marike1@optonline.net>:
> <%= submit_to_remote("search", "Search",
>                     :url => {:controller => "search", :action =>
> "search_artists"},
>                     :html => {:class => 'search'},
>                     :update => :item,
>                     :method => 'get') %>)
>
> </form>
> <div id="item"></div>

You know what I would do ?  I would put the target of the action in a
hidden field, and read that hidden field in the submit_to_remote.
Change your :url to:
:url => %Q($('id_of_hidden_field').value)

WARNING: untested - I don't even know if that'll work.  Worth a try,
don't you think ?

Bye !
François
This topic is locked and can not be replied to.