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

Andrew picture Andrew · Dec 2, 2013 · Viewed 18k times · Source

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.

Answer

Bubbles picture Bubbles · Dec 2, 2013

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

<%= render @user.microposts %>