small medium large xlarge

13 Aug 2008, 21:24
Dan Pendergrass (11 posts)

C:\rubydev\ch07\depot>ruby -v ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]

C:\rubydev\ch07\depot>rails -v Rails 2.1.0

After making changes to hide the sidebar I couldn’t get anything to display in it. My log file gives the following. Processing StoreController#add_to_cart (for at 2008-08-13 14:05:08) [POST] Session ID: f7a8c3177d55cff8597253463846ac74 Parameters: {“commit”=>”Add to Cart”, “authenticity_token”=>”c51678e67613b79018fd39c428ecaba166cc8442”, “action”=>”add_to_cart”, “id”=>”2”, “controller”=>”store”} Attempt to access invalid product 2 Redirected to http://localhost:3000/store Completed in 0.01500 (66 reqs/sec) | DB: 0.04700 (313%) | 302 Found [http://localhost/store/add_to_cart/2]

Processing StoreController#index (for at 2008-08-13 14:05:09) [GET] Session ID: f7a8c3177d55cff8597253463846ac74 Parameters: {“action”=>”index”, “controller”=>”store”} Product Load (0.000000) SELECT * FROM products ORDER BY title Rendering template within layouts/store Rendering store/index Product Columns (0.016000) SHOW FIELDS FROM products Rendered store/_cart (0.00000) Completed in 0.01600 (62 reqs/sec) | Rendering: 0.00000 (0%) | DB: 0.04700 (293%) | 200 OK [http://localhost/store]

Something odd I’ve noticed is that my id’s now go from 2 to 4 when I would have thought they would go from 0 to 2 or 1 to 3. They also are not in order on the index display.

I’m sure this is something stupid, but I’ve been working on this so long I can’t see straight.

Really appreciate any thoughts you might have.


13 Aug 2008, 23:22
Sam Ruby (634 posts)

Nothing obvious jumps out, so lets get more data. From the command line, type ruby script/console, and at the prompt type the following script and see if your output looks anything like mine:

>> Product.find_by_sql('select title, id from products')
=> [#<Product id: 2, title: "Pragmatic Project Automation">, #<Product id: 3, title: "Pragmatic Version Control">, #<Product id: 4, title: "Pragmatic Unit Testing (C#)">]

Even if the ids are different, compare them to what you see when you do a view-source on http://localhost:3000/store/. Look for <h3> elements containing your titles, and <form action="/store/add_to_cart/n"> elements where the n’s should match your ids.

Finally, back in script console, try

>> Product.find(2)

None of these actions will likely provide the answer, but hopefully they will identify questions that will help decide where to explore next.

14 Aug 2008, 17:56
Dan Pendergrass (11 posts)

They seem to match. Here’s the console output and the first product from the page source.

>> Product.find_by_sql('select title, id from products')
=> [#<Product id: 2, title: "Pragmatic Project Automation">, #<Product id: 3, ti
tle: "Pragmatic Version Control">, #<Product id: 4, title: "Pragmatic Unit Testi
ng (C#)">]

			<h3>Pragmatic Project Automation</h3>
       <em>Pragmatic Project Automation</em> shows you how to improve the 
       consistency and repeatability of your project's procedures using 
       automation to reduce risk and errors.

        Simply put, we're going to put this thing called a computer to work 
        for you doing the mundane (but important) project stuff. That means 
        you'll have more time and energy to do the really 
        exciting---and difficult---stuff, like writing quality code.
			<span class="price" >$29.95</span>
			<form action="/store/add_to_cart/2" method="post" onsubmit="new Ajax.Request('/store/add_to_cart/2', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;"><div style="margin:0;padding:0"><input name="authenticity_token" type="hidden" value="c51678e67613b79018fd39c428ecaba166cc8442" /></div>
				<input name="commit" type="submit" value="Add to Cart" />
>> Product.find(2)
=> #<Product id: 2, title: "Pragmatic Project Automation", description: "<p>\n
     <em>Pragmatic Project Automation</em> sh...", image_url: "/images/auto.jpg"
, created_at: "2008-08-08 20:16:21", updated_at: "2008-08-08 20:16:21", price: #


My hat’s off to you if you can figure something out from this. Everything looks sano from where I sit. My guess is that one of my controlling files aren’t getting the id value passed in (correctly), but I couldn’t see where I made any mistakes. I’m going to walk back through them now to see if I was just too bugeyed to see the obvious.

Thanks for the patience and support!

Ok, I looked in my DOM inspector and it shows the following:

nodeName nodeValue onsubmit new Ajax.Request(‘/store/add_to_cart/2’,{asynchronous:true,evalScripts:true,parameters:Form.serialize(this)}); return false; method post action /store/add_to_cart/2

more info Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 5.0.51b-community-nt MySQL Community Edition (GPL)

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20080702 Firefox/ WinXP SP3

14 Aug 2008, 19:44
Dan Pendergrass (11 posts)

Sam, in snooping around I’m noticing that working on windows is problematic and I’m beginning to wonder if there isn’t glitch here. I don’t intend to deploy on windows (ironically one reason I choose to do the tutorial on Winbloat was that I often have to adjust tutorials for Linux use - sheesh). However, one thing that concerns me is that the server I will have to work on in production runs TomCat and I’m not certain how that will work with RoR, so I was going to wait until I had a better handle on this. If you think that this may actually be a windows only problem then I’ll just build a virtual RHEL server and work the tutorial in that.


14 Aug 2008, 22:07
Dan Pendergrass (11 posts)

Found problem

current_item « in cart.rb

should have been

current_item =

so much pain …….

You must be logged in to comment