small medium large xlarge

Generic-user-small
11 May 2016, 17:32
Andrew Mwenechanya (3 posts)

Hi, everyone I’m following along the book, but can’t continue because of a problem. I’m having problems with the partials, instead of rendering the partials rails wants to have an ActiveModel object where it is supposed to render a collection.

ActionView::Template::Error: ‘nil’ is not an ActiveModel-compatible object. It must implement :to_partial_path.

I did everything according to the book but still get this error in the productscontroller, line_itemscontroller and cartscontroller where the partial is to be rendered.

Now before i post the code i wanted to know if there had been changes in rails on partials implemention. I’m using rails 4.2.6 and ruby 2.2.4. The error occurs in the application.html.erb.

Code that is causing the error in main layout: <div id="cart"> <%= render @cart %></div>

thanks in advance…

Samr_small_pragsmall
11 May 2016, 17:41
Sam Ruby (634 posts)

I’m showing tests passing on 4.2: http://intertwingly.net/projects/dashboard.html

Generic-user-small
12 May 2016, 21:47
Andrew Mwenechanya (3 posts)

I have matched my code to be the same as yours Sam Ruby but the errors haven’t gone. When I first load the app it appears to be fine but when i go to localhost:5000/products, carts and line_items
the error comes again. Rake test shows the errors too.

thx

Generic-user-small
17 May 2016, 20:25
Andrew Mwenechanya (3 posts)

Found a solution.

changed code from <%= render @cart %> to <%= render partial: “cart” , collection: @cart %> and the errors are gone now!

But now if i reload the store#index page the cart disappears any clue on how to fix this? And when i add an item the cart reappears updated on the sidebar.

Could it be a caching problem?

You must be logged in to comment