small medium large xlarge

14 Mar 2013, 10:06
mike-b (2 posts)

Following tutorial w/ rails 4.0.beta and ruby 2.0. In the chapter 12 checkout section when I click checkout I get the below error instead of figure 22 on page 166. Have others experienced this? If so send a solution. Thanks.

NoMethodError in OrdersController#new

undefined method `line_items’ for nil:NilClass

error points to this line in the orders controller

if @cart.line_items.empty?
14 Mar 2013, 12:03
Sam Ruby (614 posts)

This is an error in the current printing of the book, and will be fixed in the next printing.

The error messages you are getting indicates that @cart has a value of nil, as that is the object to which you are sending the line_items method.

To correct this, add the following lines at the top of the file:

include CurrentCart
before_action :set_cart, only: [:new, :create]


You can see what the result looks like at the following URL:

You must be logged in to comment