Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

" 'nil' is not an ActiveModel-compatible object. It must implement :to_partial_path " error in micropost model

When I attempt to view the user profile page, I get the error above.

Here's my show.html.erb code:

<% provide(:title, @user.name) %>

<div class="row">

  <aside class="span4">
    <section>
      <h1>
        <%= gravatar_for @user %>
        <%= @user.name %>
      </h1>
    </section>
  </aside>

  <div class="span8">
    <% if @user.microposts.any? %>
      <h3>Microposts (<%= @user.microposts.count %>)</h3>
      <ol class="microposts">
        <%= render @microposts %>
      </ol>
      <%= will_paginate @microposts %>
    <% end %>
  </div>

</div>

where <%= render @microposts %> is causing the problem.

like image 930
Andrew Avatar asked Dec 02 '13 04:12

Andrew


1 Answers

Do you declare the variable @microposts anywhere? At a glance, looks like what you should be doing is

<%= render @user.microposts %>
like image 163
Bubbles Avatar answered Sep 21 '22 12:09

Bubbles