small medium large xlarge

Generic-user-small
15 Sep 2010, 17:05
Bryan Becker (1 post)

I had to change computers while studying, so I decided to create a new reals app, and then copy the code from the folder depot_i in, and then run a rake, so that I could jump back in where I left off.

The problem is that the ‘add to cart’ button seems to make an error. When pressed, I get:

NoMethodError in Carts#show

Showing /home/bryan/websites/depot/app/views/carts/show.html.erb where line #6 raised:

undefined method `title' for nil:NilClass
Extracted source (around line #6):

3:   <% for item in @cart.line_items %>
4:     <tr>
5:       <td><%= item.quantity %>&times;</td>
6:       <td><%= item.product.title %></td>
7:       <td class="item_price"><%= number_to_currency(item.total_price) %></td>
8:     </tr>
9:   <% end %>

Any clue where this is coming from? It seems the rakes have taken alright…

Samr_small_pragsmall
16 Sep 2010, 16:50
Sam Ruby (634 posts)

I copied depot_i into a new directory, ran rake db:migrate then rake db:setup, and started the server. I don’t see this problem.

Looking at your output, it appears that there exists a line_item with nil as the value for product.

Generic-user-small
19 Sep 2010, 14:34
david cates (3 posts)

I get something similar:

NoMethodError in Products#index

Showing /Users/davidc1947/rails/depot/app/views/layouts/application.html.erb where line #21 raised:

undefined method `model_name’ for NilClass:Class Extracted source (around line #21):

18: <div id="side"> 19: <!-- START_HIGHLIGHT --> 20: <div id="cart"> 21: <%= render @cart %> 22: </div> 23: <!-- END_HIGHLIGHT --> 24:

Application Trace | Framework Trace | Full Trace app/views/layouts/application.html.erb:21:in _app_views_layouts_application_html_erb___19591427_2191814680_0' app/controllers/products_controller.rb:15:in index’

everything worked perfectly until adding <div id="cart"> <%= render @cart %> </div> <a href=

Eye_pragsmall
01 Jan 2011, 17:46
Mike Manewitz (1 post)

Had the same issue. I ran “rake db:setup” and reseeded. Everything seems good now.

You must be logged in to comment