Hello, How i can count <li> items in div using RJS? <div id=''results''> <li id="1"> one </li> <li id="2"> two </li> <li id="3"> three </li> </div> <%= link_to_remote.......ADD %> and in add action i want to add new li item with unique ID and get <li>''s elements count? 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 Igor, Igor K. wrote:> How i can count <li> items in div using RJS? > > <div id=''results''> > <li id="1"> one </li> > <li id="2"> two </li> > <li id="3"> three </li> > </div> > <%= link_to_remote.......ADD %> > > and in add action i want to add new li item with > unique ID and get <li>''s elements count?Just count them in the controller method you invoke as you add them. Store the count in a session variable or in a table to persist your count. 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 -~----------~----~----~----~------~----~------~--~---
>> unique ID and get <li>''s elements count? > Just count them in the controller method you invoke as you add them. > Store > the count in a session variable or in a table to persist your count.I have a following code in add.rjs count = 0 page.select(''#results li'').each do |element| count = count + 1 #element.hide end page.insert_html :bottom, ''results'', "<li id=#{count.to_s}>#{a.to_s + ">>> " + count.to_s}</li>"page.visual_effect :highlight, count.to_s, :duration => 2.5 and following in view <div id="results"> <li>one</li> </div> <%= link_to_remote "add", :url => {:action => :add} %> and i always get count = 1 -- 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 Igor, Igor K. wrote:> I have a following code in add.rjs > > count = 0 > page.select(''#results li'').each do |element| > count = count + 1 > #element.hide > end > page.insert_html :bottom, ''results'', "<li id=#{count.to_s}>#{a.to_s + " > >>> " + count.to_s}</li>" > page.visual_effect :highlight, count.to_s, :duration => 2.5 > > > and following in view > <div id="results"> > <li>one</li> > </div> > <%= link_to_remote "add", :url => {:action => :add} %> > > and i always get count = 1I''m not sure I understand exactly what it is you''re trying to accomplish, but in general.... I would recomment keeping track of ''count'' in your controller method; storing / retrieving it there and making it available to your view via an instance variable. You''re not dealing with a static page of which you have no knowledge. Everything that''s on the page is put there by your app during the session. No? 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 -~----------~----~----~----~------~----~------~--~---
would recomment keeping track of ''count'' in your> controller method; storing / retrieving it there and making it available > to > your view via an instance variable. You''re not dealing with a static > pageYes, if i work with dynamic pages i can save elements count to session, but my question is connected with static pages. For example designer add one element to div, and i set count variable in controller to 1, but when designed add new element to div, again i need to change count variable. i just want to know is it possible count some elements, for example <li> by id of <div> where are they located. maybe anybody can give a advice how to set id of new element to unique value(i guess i can user time(in milliseconds) for example) 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 Igor In an action in the controller, responding to the xhr request when you do render :update to |page| I just did a page.inspect in the log and found @content_for_layout - I think you would have to do something like page.session.content_for_layout - the log is pretty ugly - you can check. But, if you have @content_for_layout you could count the occurance of <li> in that and unless you have <li> in your layout you will have the number of li''s. However, this sounds very convoluted - you would probably be better of just adding the milliseconds id for the li. cheers Ivor On 9/22/07, Igor K. <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > would recomment keeping track of ''count'' in your > > controller method; storing / retrieving it there and making it available > > to > > your view via an instance variable. You''re not dealing with a static > > page > > Yes, if i work with dynamic pages i can save elements count to session, > but my question is connected with static pages. > For example designer add one element to div, and i set count variable in > controller to 1, but when designed add new element to div, again i need > to change count variable. > i just want to know is it possible count some elements, for example > <li> by id of <div> where are they located. > > maybe anybody can give a advice how to set id of new element to unique > value(i guess i can user time(in milliseconds) for example) > > > 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 -~----------~----~----~----~------~----~------~--~---