I have some elements that could show up on the same page multiple times. Can anyone recommend a good way to do a replace_html in this case? I may have, for example, 3 posts that have been repeated on a page, all with the same id (e.g, <div id="post-11">) and I want to perform a replace_html against all of them. Doing it the normal way just replaces the first. Can someone help? Thanks! -- 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, El Gato wrote:> I may have, for example, 3 posts that have been repeated on > a page, all with the same id (e.g, <div id="post-11">) and I want > to perform a replace_html against all of them. Doing it the normal > way just replaces the first. Can someone help? Thanks!What you have is invalid HTML / XMTML. DOM ID''s must be unique within a page for either Ajax or CSS to work properly (and don''t even get me started on browser behavior in quirks mode ;-) ). Run your page source against http://validator.w3.org/. Assuming you really need to put the same post on the page multiple times, you''ll need to come up with a new naming approach. Something like sec1-post-11, sec2-post-11, etc. isn''t tough to either render or process on return. hth, 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 -~----------~----~----~----~------~----~------~--~---
Bill Walton wrote:> > What you have is invalid HTML / XMTML. DOM ID''s must be unique within a > page for either Ajax or CSS to work properly (and don''t even get me > started > on browser behavior in quirks mode ;-) ). Run your page source against > http://validator.w3.org/. Assuming you really need to put the same post > on > the page multiple times, you''ll need to come up with a new naming > approach. > Something like sec1-post-11, sec2-post-11, etc. isn''t tough to either > render > or process on return. > > hth, > BillActually, I knew that, and was originally using classes because of it, but due to the documentation, thought I''d test id with ids to see if it would work. So, is there no way to replace_html against all elements of a class? The problem with just using a unique naming scheme is that I want *all* of the elements of that class affected by the replace... I can''t think of a clean way to interrogate the page about all of these "unique" ids and change each one then. -- 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, El Gato wrote:> Actually, I knew that, and was originally using classes because of it, > but due to the documentation, thought I''d test id with ids to see if it > would work. So, is there no way to replace_html against all elements of > a class?replace_html replaces the content of a single DOM element, specified by id. To replace the contents of multiple DOM elements, you''d just iterate. That''s very easy to do in your rjs template since it allows a mix of straight ruby and rjs.> The problem with just using a unique naming scheme is that I > want *all* of the elements of that class affected by the replace... I > can''t think of a clean way to interrogate the page about all of these > "unique" ids and change each one then.Not sure what you mean by ''interrogate the page''. It sounds like maybe you''re coming from a background that''s mostly client-side js. In RoR, every thing that''s on the page, you put there from the server side where it''s very easy to keep track of. So I typically don''t think about interrogating the page, I think about interrogating the database or the session store to find out what''s on the page. In the example you''ve given so far, my impression is you''ve got one ''thing'' that appears in different sections of the page. One (not tested, and it''s early here ;-) ) approach to replacing all those elements could look something like... sections = [''sec1-'', ''sec2-'', ''sec3-] sections.each do {|this_section| element_to_replace = this_section+@post_to_replace page.replace_html(element_to_replace, ... } I''m assuming the @post_to_replace was identified in the controller method. The sections could, of course, be identified there too. hth, 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 -~----------~----~----~----~------~----~------~--~---