Torsten Schmidt
2005-Nov-07 12:35 UTC
Plz help with error in depot-app from Agile-Development Book
Hi @all, i followed the depot-app and got an error that i could not fix. the error is after adding a product to the cart with the ''Add to Cart'' Link, when the display_cart view is called. i''ve implemented all methods and i compared my source-code with the code-example from the pragprogs and i see no difference. i triple-checked all methods and could not find whats wrong here. could someone be so kind and give me a hint? Thanks, Torstello --------------------------------- Showing */store/display_cart.rhtml* where line *#6* raised: undefined method `product'' for 19.95:Float Extracted source (around line *#6*): 3: <table> 4: <% 5: for item in @items 6: product = item.product 7: -%> 8: <tr> 9: <td> <%= item.quantity %> </td> Show session dump <http://torstello.kicks-ass.org:3000/store/display_cart#> :cart: !ruby/object:Cart items: - 19.95 total_price: 19.95 flash: !map:ActionController::Flash::FlashHash {} _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Pete
2005-Nov-07 12:56 UTC
Re: Plz help with error in depot-app from Agile-Development Book
you are not putting an array of [product]s in your session under key session[:items] but [product.price] which is a float value it guess the error is somewhere in the add_to_cart action in your controller On Mon, 07 Nov 2005 13:35:45 +0100, Torsten Schmidt <torstello-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi @all, > > i followed the depot-app and got an error that i could not fix. > > the error is after adding a product to the cart with the ''Add to Cart'' > Link, > when the display_cart view is called. > > i''ve implemented all methods and i compared my source-code with the > code-example from the pragprogs and i see no difference. > i triple-checked all methods and could not find whats wrong here. > > could someone be so kind and give me a hint? > > Thanks, > Torstello > > --------------------------------- > > Showing */store/display_cart.rhtml* where line *#6* raised: > > undefined method `product'' for 19.95:Float > > Extracted source (around line *#6*): > > 3: <table> > 4: <% > 5: for item in @items > 6: product = item.product > 7: -%> > 8: <tr> > 9: <td> <%= item.quantity %> </td> > > > > Show session dump > <http://torstello.kicks-ass.org:3000/store/display_cart#> > > :cart: !ruby/object:Cart > items: > - 19.95 > total_price: 19.95 > flash: !map:ActionController::Flash::FlashHash {}
Torsten Schmidt
2005-Nov-07 14:39 UTC
Re: Plz help with error in depot-app from Agile-Development Book
Thanks for your tip Pete, i still could not find what''s wrong, here my card-methods: ----------- store_controller.rb: ---------- def add_to_cart product = Product.find(params[:id]) @cart = find_cart @cart.add_product(product) redirect_to(:action => ''display_cart'') end def display_cart @cart = find_cart @items = @cart.items end --------- cart.rb -------- class Cart attr_reader :items attr_reader :total_price def initialize @items = [] @total_price = 0.0 end def add_product(product) @items << LineItem.for_product(product) @total_price += product.price end end -------- line_item.rb ------- def self.for_product(product) item = self.new item.quantity = 1 item.product = product item.unit_price = product.price end you are not putting an array of [product]s in your session under key session[:items] but [product.price] which is a float value it guess the error is somewhere in the add_to_cart action in your controller On Mon, 07 Nov 2005 13:35:45 +0100, Torsten Schmidt <torstello@... <http://gmane.org/get-address.php?address=torstello%2dRe5JQEeQqe8AvxtiuMwx3w%40public.gmane.org>> wrote:> Hi <at> all, > > i followed the depot-app and got an error that i could not fix. > > the error is after adding a product to the cart with the ''Add to Cart'' > Link, > when the display_cart view is called. > > i''ve implemented all methods and i compared my source-code with the > code-example from the pragprogs and i see no difference. > i triple-checked all methods and could not find whats wrong here. > > could someone be so kind and give me a hint? > > Thanks, > Torstello > > --------------------------------- > > Showing */store/display_cart.rhtml* where line *#6* raised: > > undefined method `product'' for 19.95:Float > > Extracted source (around line *#6*): > > 3: <table> > 4: <% > 5: for item in <at> items > 6: product = item.product > 7: -%> > 8: <tr> > 9: <td> <%= item.quantity %> </td> > > > > Show session dump > > :cart: !ruby/object:Cart > items: > - 19.95 > total_price: 19.95 > flash: !map:ActionController::Flash::FlashHash {}_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Pete
2005-Nov-07 15:13 UTC
Re: Re: Plz help with error in depot-app from Agile-Development Book
probably you have to get rid of an previous session with crap inside... brute force: (1) delete all cookies (2) restart your browser (3) restart WEBrick On Mon, 07 Nov 2005 15:39:03 +0100, Torsten Schmidt <torstello-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for your tip Pete, > > i still could not find what''s wrong, here my card-methods: > > ----------- > store_controller.rb: > ---------- > def add_to_cart > product = Product.find(params[:id]) > @cart = find_cart > @cart.add_product(product) > redirect_to(:action => ''display_cart'') > end > > def display_cart > @cart = find_cart > @items = @cart.items > end > > > --------- > cart.rb > -------- > class Cart > > attr_reader :items > attr_reader :total_price > > def initialize > @items = [] > @total_price = 0.0 > end > > def add_product(product) > @items << LineItem.for_product(product) > @total_price += product.price > end > end > > -------- > line_item.rb > ------- > def self.for_product(product) > item = self.new > item.quantity = 1 > item.product = product > item.unit_price = product.price > end > > > you are not putting an array of [product]s in your session under key > session[:items] > but [product.price] which is a float value > > it guess the error is somewhere in the add_to_cart action in your > controller > > On Mon, 07 Nov 2005 13:35:45 +0100, Torsten Schmidt > <torstello@... > <http://gmane.org/get-address.php?address=torstello%2dRe5JQEeQqe8AvxtiuMwx3w%40public.gmane.org>> > wrote: > >> Hi <at> all, >> >> i followed the depot-app and got an error that i could not fix. >> >> the error is after adding a product to the cart with the ''Add to Cart'' >> Link, >> when the display_cart view is called. >> >> i''ve implemented all methods and i compared my source-code with the >> code-example from the pragprogs and i see no difference. >> i triple-checked all methods and could not find whats wrong here. >> >> could someone be so kind and give me a hint? >> >> Thanks, >> Torstello >> >> --------------------------------- >> >> Showing */store/display_cart.rhtml* where line *#6* raised: >> >> undefined method `product'' for 19.95:Float >> >> Extracted source (around line *#6*): >> >> 3: <table> >> 4: <% >> 5: for item in <at> items >> 6: product = item.product >> 7: -%> >> 8: <tr> >> 9: <td> <%= item.quantity %> </td> >> >> >> >> Show session dump >> >> :cart: !ruby/object:Cart >> items: >> - 19.95 >> total_price: 19.95 >> flash: !map:ActionController::Flash::FlashHash {}
Torsten Schmidt
2005-Nov-07 15:38 UTC
Re: Re: Plz help with error in depot-app from Agile-Development Book
> probably you have to get rid of an previous session with crap inside... > > brute force: > (1) delete all cookies > (2) restart your browser > (3) restart WEBrickall of this done, same error. I got stuck with this :( Any suggestions whow to debug, what is actually filled in the items[] by items << LineItem.for_product(product)? Rails give a possibility to set a breakpoint, but where do i see the actual variable-values? could i test this step by step with script/console? Sorry i''m just a beginner with rails, coming from java/eclipse programming so i need more skills to track an error down. Torstello> i still could not find what''s wrong, here my card-methods: > > ----------- > store_controller.rb: > ---------- > def add_to_cart > product = Product.find(params[:id]) > <at> cart = find_cart > <at> cart.add_product(product) > redirect_to(:action => ''display_cart'') > end > > def display_cart > <at> cart = find_cart > <at> items = <at> cart.items > end > > > --------- > cart.rb > -------- > class Cart > > attr_reader :items > attr_reader :total_price > > def initialize > <at> items = [] > <at> total_price = 0.0 > end > > def add_product(product) > <at> items << LineItem.for_product(product) > <at> total_price += product.price > end > end > > -------- > line_item.rb > ------- > def self.for_product(product) > item = self.new > item.quantity = 1 > item.product = product > item.unit_price = product.price > end >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Sven Tissot
2005-Nov-07 15:53 UTC
Re: Re: Re: Plz help with error in depot-app from Agile-Development Book
Did you check your data in the database? I had a similar problem with my orders - I deleted a product in the database, but had orders against it ... Sven On Mon, 7 Nov 2005 16:38:42 +0100, Torsten Schmidt wrote:>> probably you have to get rid of an previous session with crap >> inside... >> >> brute force: >> (1) delete all cookies >> (2) restart your browser >> (3) restart WEBrick >> > all of this done, same error. I got stuck with this :( > > Any suggestions whow to debug, what is actually filled in the > items[] by items << LineItem.for_product(product)? > > Rails give a possibility to set a breakpoint, but where do i see > the actual variable-values? > could i test this step by step with script/console? > > Sorry i''m just a beginner with rails, coming from java/eclipse > programming so i need more skills to track an error down. > > Torstello > >
Sean Schertell
2005-Nov-08 02:33 UTC
Re: Re: Plz help with error in depot-app from Agile-Development Book
I had this exact same problem at the exact same point in the Agile Rails tutorial. It was indeed a session problem. You can do it Pete''s way or alternatively, I think you can just do this (on ''nix): cd /tmp; rm -rf ruby* Lesson learned: When everything looks perfect but I still get errors, there''s probably a funky session that needs to be killed. Sean On Nov 8, 2005, at 12:13 AM, Pete wrote:> probably you have to get rid of an previous session with crap > inside... > > brute force: > (1) delete all cookies > (2) restart your browser > (3) restart WEBrick > > > On Mon, 07 Nov 2005 15:39:03 +0100, Torsten Schmidt > <torstello-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Thanks for your tip Pete, >> >> i still could not find what''s wrong, here my card-methods: >> >> ----------- >> store_controller.rb: >> ---------- >> def add_to_cart >> product = Product.find(params[:id]) >> @cart = find_cart >> @cart.add_product(product) >> redirect_to(:action => ''display_cart'') >> end >> >> def display_cart >> @cart = find_cart >> @items = @cart.items >> end >> >> >> --------- >> cart.rb >> -------- >> class Cart >> >> attr_reader :items >> attr_reader :total_price >> >> def initialize >> @items = [] >> @total_price = 0.0 >> end >> >> def add_product(product) >> @items << LineItem.for_product(product) >> @total_price += product.price >> end >> end >> >> -------- >> line_item.rb >> ------- >> def self.for_product(product) >> item = self.new >> item.quantity = 1 >> item.product = product >> item.unit_price = product.price >> end >> >> >> you are not putting an array of [product]s in your session under key >> session[:items] >> but [product.price] which is a float value >> >> it guess the error is somewhere in the add_to_cart action in your >> controller >> >> On Mon, 07 Nov 2005 13:35:45 +0100, Torsten Schmidt >> <torstello@... <http://gmane.org/get-address.php?address=torstello% >> 2dRe5JQEeQqe8AvxtiuMwx3w%40public.gmane.org>> >> wrote: >> >>> Hi <at> all, >>> >>> i followed the depot-app and got an error that i could not fix. >>> >>> the error is after adding a product to the cart with the ''Add to >>> Cart'' >>> Link, >>> when the display_cart view is called. >>> >>> i''ve implemented all methods and i compared my source-code with the >>> code-example from the pragprogs and i see no difference. >>> i triple-checked all methods and could not find whats wrong here. >>> >>> could someone be so kind and give me a hint? >>> >>> Thanks, >>> Torstello >>> >>> --------------------------------- >>> >>> Showing */store/display_cart.rhtml* where line *#6* raised: >>> >>> undefined method `product'' for 19.95:Float >>> >>> Extracted source (around line *#6*): >>> >>> 3: <table> >>> 4: <% >>> 5: for item in <at> items >>> 6: product = item.product >>> 7: -%> >>> 8: <tr> >>> 9: <td> <%= item.quantity %> </td> >>> >>> >>> >>> Show session dump >>> >>> :cart: !ruby/object:Cart >>> items: >>> - 19.95 >>> total_price: 19.95 >>> flash: !map:ActionController::Flash::FlashHash {} > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >:::: DataFly.Net :::: Complete Web Services http://www.datafly.net