Hi guys, I''ve got a little problem relating to Ajax and Rails, namely updating multiple divs! I have created a message inbox for a system I''ve developed, and when a user clicks on a message, I want the number of read messages to decrease by one (this is displayed in 2 divs in separate locations on the page), and I don''t think the :update => ''mydiv'' in ''link_to_remote'' can cope with more than one div, I have looked at the example in the pick-axe (Chapter 18, page 403-404) but it doesn''t seem to make much sense! Any help is appreciated! Cheers, Mick -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If you want to update more than one div, rjs is the best way to go. For example def some_method //some stuff render :update do |page| page.replace_html ''div1'', :partial => ''partial1'' page.replace_html ''div2, :partial => ''partial2'' end end Or you can put these calls in a rjs file (which has precedence over a .rhtml file). Greetz, Joram On 2 apr, 19:21, Mick <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi guys, > > I''ve got a little problem relating to Ajax and Rails, namely updating > multiple divs! > > I have created a message inbox for a system I''ve developed, and when a > user clicks on a message, I want the number of read messages to decrease > by one (this is displayed in 2 divs in separate locations on the page), > and I don''t think the :update => ''mydiv'' in ''link_to_remote'' can cope > with more than one div, > > I have looked at the example in the pick-axe (Chapter 18, page 403-404) > but it doesn''t seem to make much sense! > > Any help is appreciated! > > Cheers, Mick > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If you have access to Agile with Rails v. 2, it has a good tutorial on what''s called RJS templates. Basically, you use Ruby to write out javascript that gets executed on the client (the {executeScripts: true} of Prototype). Some info is also available on the api page: http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html#M000559 You can write RJS in your controller or as a partial _partial_name.rjs Note: if you do this, you must not use :update, or the resulting javascript will be printed to the page. Jason On 4/2/07, Mick <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi guys, > > I''ve got a little problem relating to Ajax and Rails, namely updating > multiple divs! > > I have created a message inbox for a system I''ve developed, and when a > user clicks on a message, I want the number of read messages to decrease > by one (this is displayed in 2 divs in separate locations on the page), > and I don''t think the :update => ''mydiv'' in ''link_to_remote'' can cope > with more than one div, > > I have looked at the example in the pick-axe (Chapter 18, page 403-404) > but it doesn''t seem to make much sense! > > Any help is appreciated! > > Cheers, Mick > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Mick, Mick wrote:> I''ve got a little problem relating to Ajax and Rails, > namely updating multiple divs!Joram is correct. You want to use RJS. And you are correct. The :update will not update more than one element. I highly recommend Cody Fauser''s RJS Tutorial on O''Reilly. It''s a $10 PDF that''s well worth the money and will have you productive and feeling comfortable in a couple of hours. Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks everyone, you''ve all been more than helpful, cheers Mick -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---