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? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Apr 26, 2011 at 8:45 AM, johnlucas <gianluca.trombetta-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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? On Apr 26, 8:29 pm, David Kahn <d...-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote:> On Tue, Apr 26, 2011 at 8:45 AM, johnlucas <gianluca.trombe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sun, May 1, 2011 at 3:36 AM, johnlucas <gianluca.trombetta-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>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.> > On Apr 26, 8:29 pm, David Kahn <d...-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote: > > On Tue, Apr 26, 2011 at 8:45 AM, johnlucas <gianluca.trombe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > >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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > > > To unsubscribe from this group, send email to > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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... On May 1, 7:55 pm, David Kahn <d...-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote:> On Sun, May 1, 2011 at 3:36 AM, johnlucas <gianluca.trombe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>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... > > 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. > > > > > > > > > > > On Apr 26, 8:29 pm, David Kahn <d...-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote: > > > 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.