small medium large xlarge

Generic-user-small
06 Aug 2008, 06:52
Max Norman (17 posts)

I went back through all of the code samples from the book, caught a few errors, but it still won’t work. What might be the problem?

Samr_small_pragsmall
06 Aug 2008, 10:34
Sam Ruby (584 posts)

Possibilities:

“app/views/layouts/store.html.erb”:http://media.pragprog.com/titles/rails3/code/depot_m/app/views/layouts/store.html.erb doesn’t include :defaults

# “app/views/store/add_to_cart.js.rjs”:http://media.pragprog.com/titles/rails3/code/depot_m/app/views/store/add_to_cart.js.rjs has a problem on the lines that defines the visual effect # “app/views/store/_cart_item.html.erb”:http://media.pragprog.com/titles/rails3/code/depot_m/app/views/store/_cart_item.html.erb isn’t setting id=”current_item” on the current item # “app/controllers/store_controller.rb”:http://media.pragprog.com/titles/rails3/code/depot_m/app/controllers/store_controller.rb isn’t setting @current_item in add_to_cart # “app/models/cart.rb”:http://media.pragprog.com/titles/rails3/code/depot_m/app/models/cart.rb isn’t setting or returning current_item.

If you have access to Firefox, one thing that might save you some time debugging is to use your mouse to select the cart (the text from “Your Cart” through the total), and then use the right mouse button and “View Selection Source”.

One of the lines should look something like the following:

<tr style="background-image: none; background-color: transparent;" id="current_item">
Generic-user-small
06 Aug 2008, 16:44
Max Norman (17 posts)

I selected the cart and viewed my selection, but there were no attributes in any of the <tr> tags. What gives?

Samr_small_pragsmall
06 Aug 2008, 20:21
Sam Ruby (584 posts)

If there aren’t any attributes, then we know that #3 in the list above isn’t happening. It could be a problem in _cart_item.html.erb, or it could be a problem in store_controller.rb (#4) or cart.rb (#5).

If you can’t visually spot the problem, try downloading those three files and replacing your copy with the downloaded copy.

Generic-user-small
06 Aug 2008, 23:11
Max Norman (17 posts)

I’ve replaced all three of the files, but it still isn’t working. For me to see an addition to the cart, I need to refresh the page.

Samr_small_pragsmall
07 Aug 2008, 03:08
Sam Ruby (584 posts)

That’s a different problem, and while it may have many causes, it is common enough to have a specific Troubleshooting section included at the bottom of page 132 and continuing onto page 133.

Can you check to see if any of these hints apply to you?

Generic-user-small
08 Aug 2008, 19:12
Max Norman (17 posts)

The refreshing problem has only come up since I completed iteration D5 (9.5). Does that change anything?

Samr_small_pragsmall
08 Aug 2008, 21:23
Sam Ruby (584 posts)

If that is true, then backing out the change (to “this version”:http://media.pragprog.com/titles/rails3/code/depot_n/app/controllers/store_controller.rb) makes javascript highlighting work again?

Generic-user-small
09 Aug 2008, 17:34
Max Norman (17 posts)

It doesn’t, and it doesn’t fix the refreshing issue, either.

Generic-user-small
11 Aug 2008, 16:12
Max Norman (17 posts)

So what should I do?

Samr_small_pragsmall
11 Aug 2008, 17:16
Sam Ruby (584 posts)

If you believe that the problem was introduced during D5, and yet backing out the one change that that section suggested doesn’t address the problem, then something else must have changed. And that something else wasn’t what section D5 described.

Which puts me at a bit of a disadvantage when asked to suggest what to look for.

I do suggest backing up to the Troubleshooting section in D2.

More drastic measures to consider if nothing else works: (1) a working version of every single file in your depot directory can be downloaded from media.pragprog.com site in the /titles/rails3/code/depot_n/ directory, (2) archiving your current depot directory and starting over. The second approach shouldn’t be as bad as it sounds, as all of the lessons learned so far should be fresh in your mind.

But try the troubleshooting instructions and the working copy of the application available online first.

Generic-user-small
14 Aug 2008, 19:28
KenA (16 posts)

I´m facing the same issue as Max. I also diff the files involved in iteration D3 - Highlighting Changes. My View selection source test also failed as there is no id=”current_item” for the tr tag. Also tested in IE and Firefox. If I remove the new part of the code in the add_to_cart.js.rjs file which is:

page[:current_item].visual_effect :highlight, :startcolor => “#88ff88”, :endcolor => “#114411”

I can make at least the:

page.replace_html( “cart”, :partial => “cart”, :object => @cart )

work, but together they don´t work.

Also tested for:

page[:current_item].visual_effect :highlight, :startcolor => “#88ff88”, :endcolor => “#114411” unless @cart.total_items == 1

with no success at all :-(

Generic-user-small
14 Aug 2008, 19:51
KenA (16 posts)

That´s me with a solution that at least works for me … I inserted a semi-colon in the js.rjs file like this:

page.replace_html( “cart”, :partial => “cart”, :object => @cart );

page[:current_item].visual_effect :highlight, :startcolor => “#88ff88”, :endcolor => “#114411”;

Hope this to help others too :-)

Drp_pragsmall
15 Aug 2008, 14:12
Dan Pendergrass (11 posts)

Very strange, but I was encountering something similar. I went through all the files in Aptana studio and couldn’t find a solution. I then used Araxis merge to do a line by line file compare between the Pragprog files and mine. Other than some comments the only thing I found was in the add_to_cart.js.rjs file. There were two lines pre-pended with # START_HIGHLIGHT and #END_HIGHLIGHT. These were annoying me in the display so I zapped them. Nothing else seemed out of order. I wnet back and restarted everything and all is working well now. Doesn’t make any sense to me, but I’mgoing to keep an eye on this.

Samr_small_pragsmall
15 Aug 2008, 18:12
Sam Ruby (584 posts)

Other than some comments the only thing I found was in the add_to_cart.js.rjs file. There were two lines pre-pended with # START_HIGHLIGHT and #END_HIGHLIGHT.</blockquote>

URL? I just checked depot_l through depot_r, and I don’t see this.

Drp_pragsmall
15 Aug 2008, 18:24
Dan Pendergrass (11 posts)

I downloaded it from depot_n. The odd thing is that it didn’t show up when I was searching for via the OS and two different editors didn’t show it either. But it was displaying in the side bar and annoying me. I ONLY saw it when I used Araxis merge.

http://media.pragprog.com/titles/rails3/code/depot_n/app/views/store/add_to_cart.js.rjs

I just went to this and looked, but the tags weren’t there. All I can tell you is that they didn’t show up until I did the download and that I certainly didn’t put them in there. At this point I’ve already synced up the code so the evidence is gone and I’ve moved on, but they came in somewhere along the line without me doing it. Go figure.

  You must be logged in to comment