One click two actions

New to RoR here. I need to execute two actions with one click. Basically when a link/button is clicked, I need to populate two different div in the same page, both of them being two different resources. I would like to do this in AJAX.

So far I could do the job with one resource. I have one controller called "map", this is the erb that it shows when its index method is called:

<div id="columns">   <div id="side">     <div id="university">       <% if @university %>         <%= render @university %>       <% end %>     </div>   </div>

  <div id="main">     <table>     <% @universities.each do |university| %>       <tr>         <td><%= university.name %></td>         <td><%= university.city %></td>         <td><%= link_to 'Summary', university, :remote => true %></td>       </tr>     <% end %>     </table>   </div> </div>

The div "university" is rendered correctly with AJAX, I have a _university.html.erb view in the universities view folder. What I would like to do now is to populate a second div clicking the button summary, one click two actions, something like the following:

<div id="columns">   <div id="side">     <div id="university">       <% if @university %>         <%= render @university %>       <% end %>     </div>   </div>

  <div id="main">     <table>     <% @universities.each do |university| %>       <tr>         <td><%= university.name %></td>         <td><%= university.city %></td>         <td><%= link_to 'Summary', university, :remote => true %></td>       </tr>     <% end %>     </table>

    <div id="infoWindow2">       <% if @data_point_entry %>         <%= render @data_point_entry%>       <% end %>     </div>   </div> </div>

What do you suggest to do in this case? I thought I could use a custom action in the map controller that would take care of displaying both divs but then I wouldn't know how to deal with AJAX. On the top of that, I don't know if this would be a best practice.

Suggestions?

New to RoR here. I need to execute two actions with one click.

Basically when a link/button is clicked, I need to populate two

different div in the same page, both of them being two different

resources. I would like to do this in AJAX.

So far I could do the job with one resource. I have one controller

called “map”, this is the erb that it shows when its index method is

called:

    <div id="side">

            <div id="university">

                    <% if @university %>

                            <%= render @university %>

                    <% end %>

            </div>

    </div>



    <div id="main">

            <table>

            <% @universities.each do |university| %>

                    <tr>

                            <td><%= [university.name](http://university.name) %></td>

                            <td><%= university.city %></td>

                            <td><%= link_to 'Summary', university, :remote => true %></td>

                    </tr>

            <% end %>

            </table>

    </div>

The div “university” is rendered correctly with AJAX, I have a

_university.html.erb view in the universities view folder. What I

would like to do now is to populate a second div clicking the button

summary, one click two actions, something like the following:

    <div id="side">

            <div id="university">

                    <% if @university %>

                            <%= render @university %>

                    <% end %>

            </div>

    </div>



    <div id="main">

            <table>

            <% @universities.each do |university| %>

                    <tr>

                            <td><%= [university.name](http://university.name) %></td>

                            <td><%= university.city %></td>

                            <td><%= link_to 'Summary', university, :remote => true %></td>

                    </tr>

            <% end %>

            </table>



            <div id="infoWindow2">

                    <% if @data_point_entry %>

                            <%= render @data_point_entry%>

                    <% end %>

            </div>

    </div>

What do you suggest to do in this case? I thought I could use a custom

action in the map controller that would take care of displaying both

divs but then I wouldn’t know how to deal with AJAX. On the top of

that, I don’t know if this would be a best practice.

Yeah, I would recommend using jquery ajax calls. The button could call a javascript method which calls your ajax methods to the server, and populate the response into your page. If this is all new, I would suggest to first get one of the requests working, and then add in the second.

Thank you for the suggestion. This is new for me and I don't have a strong experience with Ajax and JQuery, I just played around a bit with them in some php project.

Could you point me to a comprehensive guide or tutorial?

Thank you for the suggestion. This is new for me and I don’t have a

strong experience with Ajax and JQuery, I just played around a bit

with them in some php project.

Could you point me to a comprehensive guide or tutorial?

Well, first the jquery documentation is pretty good:

http://api.jquery.com/jQuery.ajax/

Also here is one tutorial I found when I googled right now:

http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/

But you should google around (try keywords ‘jquery ajax’ or the like)… and see what you find that appeals to you.

Its not that complicated… just start with the basic of getting a remote call to work (i.e. sending a get request for a page via jquery/javascritpt). Once you see how this works then you can start working it in to your project.

I am not sure about ‘comprehensive’, maybe a book? But you can definitely pick up what you need from the web but may be in pieces.

Cool, thanks!

With 'comprehensive' I meant a guide that would explain how to work in Ajax and Ruby on Rails, something like Agile Web Development with RoR, although it maybe asking to much, that book is amazing...