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

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

Here is 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 %> causes the problem.

+6
source share
2 answers

Do you @microposts variable anywhere? At a glance, it looks like what you should do is

 <%= render @user.microposts %> 
+6
source

I have the same problem

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

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

Update: I found that the show action is defined twice (one of them defines @microposts ). To solve this problem, I simply deleted the second show action, which @microposts does not detect. I wonder how several people could duplicate the action of the show.

+1
source

Source: https://habr.com/ru/post/959144/


All Articles