On Tue, Apr 26, 2011 at 8:45 AM, johnlucas <gianluca.trombe...@gmail.com>wrote:

> 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.
>

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.


>
> Suggestions?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to