small medium large xlarge

13 Jun 2008, 22:31
Dan Steinicke (6 posts)

I’ve been enjoying the book and learning a lot but now I’m stuck. Could someone help me understand what is going wrong and how I can fix this? (I don’t think this is an issue with the book, I think I made a mistake somewhere.)

On page 174, the beginning of the F4 iteration the book(B.13) instructs you to add the line:

layout “store”

to the top of controllers/application.rb. When I do this I start getting the error below when visiting the admin page. It looks like the cart is set to nil. In the server console I see messages indicating that the AdminController is run, but no message saying the StoreController is run. If the StoreController isn’t running it makes sense that the cart isn’t getting set, but beyond that I am lost as how to troubleshoot & fix this, ie why the StoreController isn’t running or how the cart is supposed to get set some other way.

Here is the activity in my server console showing the error and proceeding actions:

** Mongrel 1.1.5 available at ** Use CTRL-C to stop.

Processing AdminController#index (for at 2008-06-13 07:19:55) [GET] Session ID: 50e435f623f4a84b2d6d45875d4e52d4 Parameters: {“action”=>”index”, “controller”=>”admin”} User Columns (0.001503) SHOW FIELDS FROM users User Load (0.000159) SELECT * FROM users WHERE ( IS NULL) LIMIT 1 Redirected to Filter chain halted as [:authorize] rendered_or_redirected. Completed in 0.01228 (81 reqs/sec) | DB: 0.00402 (32%) | 302 Found []

Processing AdminController#login (for at 2008-06-13 07:19:55) [GET] Session ID: 50e435f623f4a84b2d6d45875d4e52d4 Parameters: {“action”=>”login”, “controller”=>”admin”} Rendering template within layouts/store Rendering admin/login

ActionView::TemplateError (You have a nil object when you didn’t expect it! The error occurred while evaluating nil.items) on line #16 of layouts/store.html.erb:

13:   </div>
14:   <div id="columns">
15:     <div id="side">
16:       <% hidden_div_if(@cart.items.empty?, :id => "cart") do %> 
17:         <%= render(:partial => "cart", :object => @cart) %>
18:       <% end %> 
19:       <a href="http://www....">Home</a><br/>
13 Jun 2008, 18:59
Dan Steinicke (6 posts)

I finally solved this. views/layouts/store.html.erb was missing an “if” statement before the hidden_div_if that was causing the error. By inserting this line:

<% if @cart %>

before line 16 above, line 16 is prevented from running when the @cart is not set. (I also had to add an additional <% end %>).

13 Jun 2008, 21:32
Sam Ruby (633 posts)

My apologizes. Those lines are present on page 175 (and the text on page 174 tells you that you need to make these changes), but there aren’t little triangles next to these two lines to draw your attention to them.

This will be corrected in the next beta.

You must be logged in to comment