I recently got a copy of the second addition in PDF and got stuck on the Ajax portion using highlighting page 128. While trying to make my cart flash I got an RJS error when I click add to cart. I have gone back and made sure my code matched what was in the book but no help. I sent Dave an email and he rec''d this list. Anybody got any good links for troubleshooting Ajax or maybe have see this book and have an idea about petty problems I may have over looked? I really hate to skip past this without finding out where I went wrong. TIA Tom __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
What''s the error , maybe show the code here. Also, did you copy the code from the book or download it from the site ? If you did not download, try that as well. Stuart On 7/18/06, Tom Atkins <tomdatkins@yahoo.com> wrote:> I recently got a copy of the second addition in PDF > and got stuck on the Ajax portion using highlighting > page 128. While trying to make my cart flash I got an > RJS error when I click add to cart. I have gone back > and made sure my code matched what was in the book but > no help. I sent Dave an email and he rec''d this list. > Anybody got any good links for troubleshooting Ajax or > maybe have see this book and have an idea about petty > problems I may have over looked? > > I really hate to skip past this without finding out > where I went wrong. > TIA > Tom > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Did you forget... <%= javascript_include_tag :defaults %> in your layout, or the page. This is a gotcha that gets me every so often :) ~Jamie On 7/18/06, Tom Atkins <tomdatkins@yahoo.com> wrote:> > I recently got a copy of the second addition in PDF > and got stuck on the Ajax portion using highlighting > page 128. While trying to make my cart flash I got an > RJS error when I click add to cart. I have gone back > and made sure my code matched what was in the book but > no help. I sent Dave an email and he rec''d this list. > Anybody got any good links for troubleshooting Ajax or > maybe have see this book and have an idea about petty > problems I may have over looked? > > I really hate to skip past this without finding out > where I went wrong. > TIA > Tom > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060718/a293b934/attachment-0001.html
On 7/18/06, Tom Atkins <tomdatkins@yahoo.com> wrote:> Anybody got any good links for troubleshooting AjaxFirebug is good for debugging javascript: http://www.joehewitt.com/software/firebug/ -- Greg Donald http://destiney.com/
"Did you forget... <%= _javascript_include_tag :defaults %>" Nope first thing I checked and I first typed it, got a problem then went and downloaded the files and got the same error. I haven''t tried the firefox, I will today. Attached is a screenshot of the error, looks like it just spills it''s guts. Great email list, gonna take me a few days just reading some of these threads. Thanks for all the feedback, Tom --- Greg Donald <gdonald@gmail.com> wrote:> On 7/18/06, Tom Atkins <tomdatkins@yahoo.com> wrote: > > Anybody got any good links for troubleshooting > Ajax > > Firebug is good for debugging javascript: > > http://www.joehewitt.com/software/firebug/ > > > -- > Greg Donald > http://destiney.com/ > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- A non-text attachment was scrubbed... Name: RJS error.gif Type: image/gif Size: 23089 bytes Desc: 1286225036-RJS error.gif Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060719/785eb4c0/RJSerror-0001.gif
Tom Atkins wrote:> "Did you forget... > > <%= _javascript_include_tag :defaults %>" > > Nope first thing I checked and I first typed it, got a > problem then went and downloaded the files and got the > same error. > > I haven''t tried the firefox, I will today. > Attached is a screenshot of the error, looks like it > just spills it''s guts. > > Great email list, gonna take me a few days just > reading some of these threads. > > Thanks for all the feedback, > Tom >I''m sure I had this problem! But I can''t remember what the problem was.. I think that I had forgotten to change the file "app/views/store/index.html" - the mistake I had made was that I did not change it to have the "form_remote_tag" Hope that helps. For what it''s worth, that example does work (it did work for me) and I did not download the code from the net (so, the code in the book is correct).. you''re probably missing something. Cheers mohit.
Just tried it with Firefox and actually got some info. What I''m trying to do is make the items in the cart flash when something is added. The error is like this: TypeError: $("current_item") has no properties So atleast I know that it has a problem with the current_item. Here is my /model/cart.rb file: #--- # Excerpted from "Agile Web Development with Rails, 2nd Ed." # We make no guarantees that this code is fit for any purpose. # Visit http://www.pragmaticprogrammer.com/titles/rails2 for more book information. #--- class Cart include Reloadable attr_reader :items def initialize @items = [] end def add_product(product) current_item = @items.find {|item| item.product =product} if current_item current_item.increment_quantity else current_item = CartItem.new(product) @items << current_item end current_item end def total_price @items.inject(0) { |sum, item| sum + item.price } end end and the RJS from my /views/store/add_to_cart.rjs: page[:cart].replace_html :partial => ''cart'', :object => @cart page[:current_item].visual_effect :highlight, :startcolor => "#88ff88", :endcolor => "#114411" So I''m confused it looks like I have defined current_item correctly? or should it be in the store_controller.rb? Tom --- Tom Atkins <tomdatkins@yahoo.com> wrote:> "Did you forget... > > <%= _javascript_include_tag :defaults %>" > > Nope first thing I checked and I first typed it, got > a > problem then went and downloaded the files and got > the > same error. > > I haven''t tried the firefox, I will today. > Attached is a screenshot of the error, looks like it > just spills it''s guts. > > Great email list, gonna take me a few days just > reading some of these threads. > > Thanks for all the feedback, > Tom > > > > --- Greg Donald <gdonald@gmail.com> wrote: > > > On 7/18/06, Tom Atkins <tomdatkins@yahoo.com> > wrote: > > > Anybody got any good links for troubleshooting > > Ajax > > > > Firebug is good for debugging javascript: > > > > http://www.joehewitt.com/software/firebug/ > > > > > > -- > > Greg Donald > > http://destiney.com/ > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam > protection around > http://mail.yahoo.com >_______________________________________________> Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Tom Atkins wrote:> The error is like this: > > TypeError: $("current_item") has no propertiesIs "current_item" in fact a DOM node with id "current_item"? Is it a table row? -- Posted via http://www.ruby-forum.com/.
I''m new to this so I''m trying to make sure I know what I''m doing, at this point that''s very little: "Is "current_item" in fact a DOM node with id> "current_item"? Is it a > table row?"Is it a data object model and does it have an ID? SOme of this is kinda spinning me until I''m dizzy but according to the book: I need to flag the current item so /models/cart.rb has this: def add_product(product) current_item = @items.find {|item| item.product =product} if current_item current_item.increment_quantity else current_item = CartItem.new(product) @items << current_item end current_item end Next I need to pass that info down to the template so my /controller/store_controller.rb has this in it: def add_to_cart begin @product = Product.find(params[:id]) rescue logger.error("Attempt to access invalid product #{params[:id]}") redirect_to_index("Invalid product") else @cart = find_cart @current_item = @cart.add_product(@product) end end So product has an ID, then current_item is set the product. So I''m not sure. Tom --- Greg <gmacgregor+rubyforum@gmail.com> wrote:> Tom Atkins wrote: > > The error is like this: > > > > TypeError: $("current_item") has no properties > > Is "current_item" in fact a DOM node with id > "current_item"? Is it a > table row? > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
I''m having exactly the same problem, did this get resolved? -- 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 -~----------~----~----~----~------~----~------~--~---
The problem is that you''ve got @current_item defined as an object in the controller, and you''re trying to reference it as an item in the page. The line @current_item = @cart.add_product(@product) is returning a reference to the database information about the item you''re adding to your cart. Then, when you do page[:current_item], that is trying to find something in the html of your page that is called "current_item"... it''s referencing the database object that you have stored as @current_item. What you need to do is figure out some way to have your partial that is rendering the cart tag the item you just added with "id=''current_item''". I''m not sure how that partial is rendering your cart, so I couldn''t tell you for sure how to go about doing that. Tom Atkins wrote:> I''m new to this so I''m trying to make sure I know what > I''m doing, at this point that''s very little: > > "Is "current_item" in fact a DOM node with id >> "current_item"? Is it a >> table row?" > Is it a data object model and does it have an ID? > SOme of this is kinda spinning me until I''m dizzy but > according to the book: > I need to flag the current item so /models/cart.rb has > this: > def add_product(product) > current_item = @items.find {|item| item.product => product} > if current_item > current_item.increment_quantity > else > current_item = CartItem.new(product) > @items << current_item > end > current_item > end > > Next I need to pass that info down to the template so > my /controller/store_controller.rb has this in it: > def add_to_cart > begin > @product = Product.find(params[:id]) > rescue > logger.error("Attempt to access invalid product > #{params[:id]}") > redirect_to_index("Invalid product") > else > @cart = find_cart > > @current_item = @cart.add_product(@product) > > end > end > > So product has an ID, then current_item is set the > product. So I''m not sure. > > Tom > > --- Greg <gmacgregor+rubyforum-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com-- 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 -~----------~----~----~----~------~----~------~--~---
Doh, I typoed, please read this one instead: The line @current_item = @cart.add_product(@product) is returning a reference to the database information about the item you''re adding to your cart. Then, when you do page[:current_item], that is trying to find something in the html of your page that is called "current_item"... it''s NOT(<- missed this the first time, it''s kinda important) referencing the database object that you have stored as @current_item. What you need to do is figure out some way to have your partial that is rendering the cart tag the item you just added with "id=''current_item''". I''m not sure how that partial is rendering your cart, so I couldn''t tell you for sure how to go about doing that. -- 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 -~----------~----~----~----~------~----~------~--~---
So it is the partial that is not picking up ''current_item''? Here''s the partial: <% if cart_item == @current_item %> <tr id="current_item"> <% else %> <tr> <% end %> <td><%= cart_item.quantity %>×</td> <td><%= h(cart_item.title) %></td> <td class="item-price"><%= number_to_currency(cart_item.price) %></td> </tr> it''s called_cart_item.rhtml It looks ok to me but I''m new to partials and ruby on rails. -- 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 -~----------~----~----~----~------~----~------~--~---
Wow, I''ve got it sorted. $(current_item) had no properties because the store controller wasn''t passing it any because I had typed the code wrong: @current_item == @cart.add_product(product) should have been: @current_item = @cart.add_product(product) @current_item could not have had any properties unles it was equal to @cart.add_product(product). It should just be the same as @cart.add_product(product). (if that makes sense!) Thanks Luke, you got me thinking as to why there was no properties, thanks again for your help. -- 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 -~----------~----~----~----~------~----~------~--~---
I am having the same problem. I figured out @current_item is not equal to ''cart_item''. So, if you set the ''if'' block like below, you can see the effects working, <% if cart_item == @current_item %> <tr id="current_item"> <% else %> <tr id="current_item"> <% end %> But, my main concern is, why ''cart_item == @current_item'' is false. Anyone solved this case...? -Arul james seavers wrote:> So it is the partial that is not picking up ''current_item''? Here''s the > partial: > > <% if cart_item == @current_item %> > <tr id="current_item"> > <% else %> > <tr> > <% end %> > <td><%= cart_item.quantity %>×</td> > <td><%= h(cart_item.title) %></td> > <td class="item-price"><%= number_to_currency(cart_item.price) %></td> > </tr> > > it''s called_cart_item.rhtml > > It looks ok to me but I''m new to partials and ruby on rails.-- 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 -~----------~----~----~----~------~----~------~--~---
Arulchandran P wrote:> I am having the same problem. I figured out @current_item > is not equal to ''cart_item''. So, if you set the ''if'' block > like below, you can see the effects working, > > <% if cart_item == @current_item %> > <tr id="current_item"> > <% else %> > <tr id="current_item"> > <% end %> > > But, my main concern is, why ''cart_item == @current_item'' is false. > Anyone solved this case...? > > -Arul >Could you check your Cart model? Be sure that add_product function looks like def add_product(product) current_item = @items.find {|item| item.product == product} if current_item current_item.increment_quantity else current_item = CartItem.new(product) @items << current_item end current_item end and not: def add_product(product) current_item = @items.find {|item| item.product == product} if current_item current_item.increment_quantity else @items << CartItem.new(product) end current_item end It''s possible that you''re returning nil. -- 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 -~----------~----~----~----~------~----~------~--~---