11

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.

Andrew
  • 3,839
  • 10
  • 29
  • 42

2 Answers2

8

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

<%= render @user.microposts %>
Bubbles
  • 3,795
  • 1
  • 24
  • 25
2

I have the same issue

yes, the @microposts is declared in the controller show method as:

def show
  @user = User.find(params[:id])
  @microposts = @user.microposts.paginate(page: params[:page])
end

Update: I've found that the show action is defined twice (one of them defines @microposts). To solve this issue, I simply removed the second show action which doesn't define @microposts. I wonder how more than one person could have managed to duplicate the show action.

Habib
  • 279
  • 1
  • 2
  • 9