small medium large xlarge


I refactored a lot of the Second Edition content to match the Fourth Edition. Below is orphaned content that is not in the Fourth Edition.

The following pages still exist and can be deleted. All orphaned second edition content from them is below:

Installation (Second Edition)

I encountered an installation issue when installing Rails on OS X – following the instructions for This article provided some insight for a patch:

This fixes the installation of gem install mysql which installs successfully albiet with errors

Make sure you read the latest article!!! They don’t delete the old ones. There are several newer ones. the best thing to do is start from the home page of

Rails 2.3.5 rack version !=1.0.1 mismatch

If you encounter a mismatched version of rack when trying to start the local rails 2.3.5 server, try the following:

gem uninstall rack
gem install rack -v 1.0.1


Write a page for the say application that illustrates the looping you can do in ERb. Discuss

Experiment with adding and removing the minus sign at the end of the ERb <= %> sequence (i.e., changing %> into ->, and vice versa. Use your browser’s View → Source option to see the difference. Discuss

A call to the following Ruby method returns a list of all the files in the current directory.

@files = Dir.glob('*') 

Use it to set an instance variable in a controller action, and then write the corresponding template that displays the filenames in a list on the browser. Hint: in the ERb examples, we saw how to iterate n times. You can iterate over a collection using something like

<% for file in @files %>  
  file name is: <%= file %> 
<% end %> 

You might want to use a ul for the list. Discuss


Add the product price to the output of the list action. Discuss


Change the application so that clicking a book’s image will also invoke the add_to_cart action. (It’s OK, I know we haven’t written that action yet….) Hint: the first parameter to link_to is placed in the generated <a> tag, and the Rails helper image_tag constructs an HTML <img> tag. Look up image_tag in the Rails API documentation at, and include a call to it as the first parameter to a link_to call. Discuss


Trace the flow through the methods save_order, add_line_items_from_cart, and from_cart_item. Do the controller, order model, and line item model seem suitably decoupled from each other? (One way to tell is to look at potential changes—if you change something, such as by adding a new field to a cart item, does that change ripple through the code?) Can you find a way to further reduce coupling? Discuss

Working through the playtime here… Could you be more specific about what were are doing and why:

“Create a migration that copies the product price into the line item, and modify the controller to capture the price at the time of the order”

For some this may be obvious but for me, not.

Do you mean:

“Create a migration that copies the product price into the line item table, and modify the controller to capture the the price when the order is created”

The other comment I have is why… If it is to show the product price in the cart can’t we do this with adding product.price to the _line_item partial?

what does copying the product price into the line item table do for us?


Balefire says:

From what I understand, if you do not copy the product price into the line_item table and the price changes, you will not be able to reference the old price. Including when viewing orders prior to the price change. This is an unbelievably bad thing to happen from a book-keeping and maybe even a legal point of view!


Attempting to delete the last user at end of AWDWR2 11.4 results in a runtime exception raised instead of the expected flash banner display. The solution is to modify the LoginController#delete_user routine described on page 161 to match the one in the full listing on page 661. Add the begin/end blocks with a rescue clause to set the flash. This is mentioned near the bottom of page 163 but the code was not described at that point. This was in the first edition but the rescue block was lost from the second edition.

Adapt the checkout code from the previous chapter to use a single action, rather than two. Discuss


Change the original catalog display (the index action in the store controller) so that it returns an XML product catalog if the client requests an XML response. Discuss

Try using rxml templates to generate normal HTML (technically, XHTML) responses. What are the advantages and disadvantages? Discuss

If you like the programmatic generation of HTML responses, have a look at Markaby. It installs as a plugin, so you’ll be trying stuff we haven’t talked about yet, but the instructions on the web site are clear. Discuss


PEZ says: Running all functional tests (rake test:functionals) gives me lots of errors. Discuss

PEZ says: Getting the integration test “User Stories” isn’t smooth for me. Discuss

Steve D says: If you did all the Playtime at the end of Chapter 10. TASK E: CHECK OUT!, you may have done what I did, which was to change the Order model to use an integer id for payment type. If you did, you may have some trouble when you run the “ruby -I test test/unit/product_test.rb” command on page 208…... when I changed the depot\test\fixtures\orders.yml to match the field name and data type:

pay_type: MyString becomes… payment_type_id: 1

I was able to run the unit tests.


The depot example only deals with single type of products. How can we deal with stores that have various types, such as computer online shops where they provide CPU, Memory, Motherboard, Video Cards, Sound Cards, Storage, Power Supply, etc. Each category has different specification types and values.

How could we generate models that can serve similar functions? How many models we would have? And how we link those models for easy inserting, updating?

Page History
  • V16: Andrew de Andrade [over 7 years ago]
  • V15: Andrew de Andrade [over 7 years ago]
  • V14: Andrew de Andrade [over 7 years ago]
  • V13: Andrew de Andrade [over 7 years ago]
  • V12: Andrew de Andrade [over 7 years ago]
  • V11: Andrew de Andrade [over 7 years ago]
  • V10: Andrew de Andrade [over 7 years ago]
  • V9: Andrew de Andrade [over 7 years ago]
  • V8: Andrew de Andrade [over 7 years ago]
  • V7: Andrew de Andrade [over 7 years ago]