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:

<% if @university %> <%= render @university %> <% end %>
<% @universities.each do |university| %> <% end %>
<%= university.name %> <%= university.city %> <%= link_to 'Summary', university, :remote => true %>

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:

<% if @university %> <%= render @university %> <% end %>
<% @universities.each do |university| %> <% end %>
<%= university.name %> <%= university.city %> <%= link_to 'Summary', university, :remote => true %>
<div id="infoWindow2">
  <% if @data_point_entry %>
    <%= render @data_point_entry%>
  <% end %>
</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?

On Tue, Apr 26, 2011 at 8:45 AM, johnlucas
[email protected]wrote:

   <div id="side">
                   <tr>

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

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?

Cool, thanks!

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

On Sun, May 1, 2011 at 3:36 AM, johnlucas
[email protected]wrote:

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs