Multiple :url in remote_form_for.

Hi. I'm developing a Ruby Application. I would like to perform several actions, that is, call more than one action in 1 controller when someone clicks the submit_tag using ajax, rjs, etc. Right now it is working perfectly but with just one call. This is how the code looks like: <% form_remote_for :tag,               :loading => visual_effect(:appear, :loading_div),               :success => visual_effect(:fade, :loading_div),               :failure => "alert('HTTP Error ' + request.status + '!')", #visual_effect(:fade, :loading_div),               :url => {:controller => "build", :action => "parse"} do | f> %>

          Search: <%= f.text_field :title %>

                      <%= submit_tag "Submit" %>

<% end %>

So the idea is to have two :url => {:controller => "build", :action => "parse"} :url => {:controller => "build", :action => "parse2"} and when someone clicks the button to run both of them concurrently. Is this possible in any way? Thanks in advance :wink: Happy 2008 :wink:

Javier Quevedo wrote:

Hi. I'm developing a Ruby Application. I would like to perform several actions, that is, call more than one action in 1 controller when someone clicks the submit_tag using ajax, rjs, etc. Right now it is working perfectly but with just one call. This is how the code looks like: <% form_remote_for :tag,               :loading => visual_effect(:appear, :loading_div),               :success => visual_effect(:fade, :loading_div),               :failure => "alert('HTTP Error ' + request.status + '!')", #visual_effect(:fade, :loading_div),               :url => {:controller => "build", :action => "parse"} do | f> %>

          Search: <%= f.text_field :title %>

                      <%= submit_tag "Submit" %>

<% end %>

So the idea is to have two :url => {:controller => "build", :action => "parse"} :url => {:controller => "build", :action => "parse2"} and when someone clicks the button to run both of them concurrently. Is this possible in any way?

Yes, add option

:html => {:onsubmit => remote_function(:url => {:controller => 'build', :action => :parse2})}

what if I want to have 3 or 4? or 100? Thanks for your reply!

Having multiple is just stupid. If you want it to do multiple things at the same time, stick them all in the same action and only call one URL.

Not really Ryan. There is at least one case in which is interesting to do. Since you can't have more than one render per action and there are times when you want to render partials concurrently. So, is there any way to do it? I was trying another solution by creating Threads in the controller but i think that it will be easier this way. Check http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/e11f83680ee71eef to see what happens if you try to do it with multiple threads and multiple renders.

You can render as many partials as you want, concurrently.

For example: <%= render :partial => “number_1” %> <%= render :partial => “number_2” %>

If you’re using render :update in your action do a

page.replace_html :element_on_the_page, :partial => “number_1” page.replace_html :other_element_on_the_page, :partial => “number_2”

Javier Quevedo wrote:

what if I want to have 3 or 4? or 100?

You can create a JavaScript function that is called by the onsubmit event, and which calls remote_function in a loop.

Concurrency will however be limited by both the number of simultaneous connections for a browser and the number of Rails handlers you are running.

However this method does allow multiple changes to be sent to the browser concurrently, in contrast to the Thread option (in your other post), which only sends to the browser when all threads have completed.