Hi, I''m following the book Agile Web Development with Rails and I have finished to implement the action remove_from_cart which is one of the task in the Playtime section of page 139. Everything works well; I highlight the current_item which has been modify, and I even subtract the item from the cart when the quantity is = 0. However the highlight trick give an error when I extract the last item, and it make sense because there is note current_item any more. How can I make this effect happen only when quantity is > 0? Here I leave what Im doing but its not working. remove_from_cart.js ------------------ page.replace_html(cart , :partial => cart , :object => @cart) page[:cart].visual_effect :blind_up if @cart.total_items <= 0 if page[:current_item] page[:current_item].visual_effect :highlight, :startcolor => #88ff88, :endcolor => #114411 end Thanks in advance -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Whenever you want to do something with an element that may not be present on the page using the select method makes a lot of sense. It builds a collection of all the elements that can be described by some css select (hence id''s or css classes) and then you can use something like .each to iterate through the collection. Something like: page.select(''#current_item'').each{|elem| elem.visual_effect :highlight, :startcolor => "#88ff88", :endcolor => "#114411" On Nov 28, 11:54 am, Alberto Trujillo <rails-mailing-l...@andreas- s.net> wrote:> Hi, > > I''m following the book Agile Web Development with Rails and I have > finished to implement the action "remove_from_cart" which is one of the > task in the Playtime section of page 139. > > Everything works well; I highlight the current_item which has been > modify, and I even subtract the item from the cart when the quantity is > = 0. However the highlight trick give an error when I extract the last > item, and it make sense because there is note current_item any more. > > How can I make this effect happen only when quantity is > 0? > > Here I leave what I''m doing but it''s not working. > > remove_from_cart.js > ---------------------------- > page.replace_html("cart" , :partial => "cart" , :object => @cart) > > page[:cart].visual_effect :blind_up if @cart.total_items <= 0 > > if page[:current_item] page[:current_item].visual_effect :highlight, > :startcolor => "#88ff88", :endcolor => "#114411" > end > > Thanks in advance > -- > 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 -~----------~----~----~----~------~----~------~--~---
Thank you guys, Both options worked fine :) Andy: There is a missing "}" at the end of your line of code. I just mention it in case somebody else try to use it. -- 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 -~----------~----~----~----~------~----~------~--~---