small medium large xlarge

23 Jun 2012, 21:25
John McCormack (3 posts)


I’ve hit a roadblock while adding partial templates for the cart & line items. I’ve created the _line_item.html.erb & _cart.html.erb files as per the book & updated the carts/show.html.erb, application.html.erb & store_controller.rb files. Everything looks ok when I’m looking at the store page, or at the cart, but when I navigate to the home page or to a signup page that was created by my project partner, i get the following error:

‘nil’ is not an ActiveModel-compatible object that returns a valid partial path.

Extracted source (around line #23):

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

. . . .

app/views/layouts/application.html.erb:23:in `_app_views_layouts_application_html_erb__75579073554998489_70261714237260’

Any able to help?

Regards, John

20 Jul 2012, 15:49
Jens Dahl Mollerhoj (1 post)

Hi John

I am a beginner as well, and I have hit the same problem.

It seems that the @cart variable is nil. This makes sense because it is set in the store controller. That controller is only called when you go to the store, not when, for example the products page. I don’t know how to fix this. For now I have written a <% if @cart %> before the render statement, this removes the error.

For facing_pragsmall
20 Jul 2012, 20:42
Vasili Chyrvon (8 posts)

Hello! I’m not sure, but check for _cart.html.erb in the folders where the home and sign up pages is stored. If there is no such file, then you must create it here.

As I understand the @render@ comand is looking for partial ( _cart.html.erb) in the folder where is lying the page from which it was called. And if there is no such partial we have this message.

31 Jul 2012, 21:49
enrico stano (2 posts)


I’ve the same problem, and I have _cart.html.erb in /app/views/carts directory.

I don’t understand where is the problem.

bye and thank you.

02 Aug 2012, 10:42
enrico stano (2 posts)


I’ve solved this looking here


You must be logged in to comment