Agile Web Development with Rails 8_B6.0(page 148)

The file: app/views/line_items/_line_item.html.erb was created in iteration D2, when we ran the generator: bin/rails generate scaffold LineItem product:references cart:belongs_to

And it’s contents at the time were:

Product: <%= line_item.product_id %>
Cart: <%= line_item.cart_id %>

Page 148 shows the contents as:

<%= line_item.quantity %> × <%= line_item.product.title %> <%= number_to_currency(line_item.total_price) %>

I found this to be confusing. I suggest that it be noted that the existing code needs to be replaced with the new code.

This was done in iteration E1, and instead of x, you see ×

Hmm… it looks like the text editor isn’t escaping the HTML snippet that I added properly, and as a result, not really demonstrating my point.

I realize that in iteration E1 we created a quantity column to the line_items table, but in that iteration, we added it to the _cart.html.erb partial. Later, in iteration E3, we replaced the list item-based approach with a table. But that was still in the cart partial.

In iteration F1, we cleaned up the cart partial by extracting the table-based code into the _line_item.html.erb partial as shown at the bottom of page 147/top of page 148.

What I found confusing was the book shows the change from the do loop to being a render,
it doesn’t directly indicate that the code that was removed needs to replace the existing div-based code in the line_item partial.

I eventually figured it out, but felt that it was worth mentioning, as I could see someone else stumbling here as well. I find that the book is very excellently detailed in the steps that need to be performed, but felt that it was missing something here.

Or maybe it’s just a “me” thing. Thanks!