title: Undefined method, avatar and name for nil:NilClass
body: <p>undefined method <code>avatar?' for nil:NilClass
  undefined method</code>name' for nil:NilClass</p>
  
  <p>Hi, I'm receiving the following errors in my partial. The reason I listed both is because after commenting out the line causing the first error message, I get the second error which leads me to believe the problem isn't with "avatar" or "name" specifically, but with something else,though I don't know what. In rails console, I'm able to call user and name on a comment. I also seeded the database using Faker if that matters.  Here's the partial. </p>
  
  <pre><code>&lt;%= content_tag :div, class: 'media', id: "comment-#{comment.id}" do %&gt;
    &lt;%= link_to '#', class: 'pull-left' do %&gt;
      &lt;%= image_tag(comment.user.avatar.small.url) if comment.user.avatar?  %&gt;
    &lt;% end %&gt;
    &lt;div class="media-body"&gt;
      &lt;small&gt;
        &lt;%= comment.user.name %&gt; commented &lt;%= time_ago_in_words(comment.created_at) %&gt; ago
        &lt;% if policy(comment).destroy? %&gt;
          | &lt;%= link_to "Delete", [@topic, @post, comment], method: :delete %&gt;
        &lt;% end %&gt;
      &lt;/small&gt;
      &lt;p&gt;&lt;%= comment.body %&gt;&lt;/p&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Also, please see the render.</p>
  
  <pre><code>  &lt;div class="col-md-4"&gt;
      &lt;% if policy(Comment.new).create? %&gt;
        &lt;h4&gt;Leave a comment&lt;/h4&gt;
        &lt;br/&gt;
        &lt;%= render partial: 'comments/comment', locals: { topic: @topic, post: @post, comment: @comment } %&gt;
      &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The below are my user model and comments_controller</p>
  
  <pre><code>class UsersController &lt; ApplicationController
    before_filter :authenticate_user!
  
    def update
      if current_user.update_attributes(user_params)
        flash[:notice] = "User information updated"
        redirect_to edit_user_registration_path(current_user)
      else
        render "devise/registrations/edit"
      end
    end
  
    private
  
    def user_params
      params.require(:user).permit(:name, :avatar)
    end
  end
  </code></pre>
  
  <p>Comments_controller</p>
  
  <pre><code>  def create
      @topic = Topic.find(params[:topic_id])
      @post = @topic.posts.find(params[:post_id])
      @comments = @post.comments
  
      @comment = current_user.comments.build(comment_params)
      @comment.post = @post
      @new_comment = Comment.new
  
      authorize @comment
      if @comment.save
        redirect_to [@topic, @post], notice: "Comment was submitted successfully."
      else
        flash[:error] = "There was an error submitting the comment. Please try again."
      end
    end
  </code></pre>
  
  <p>I've already reset the database, but to no avail. Stuck as to what the issue is. Thanks for your help.</p>
  
  <p>Please see below for my User and Comment models.</p>
  
  <pre><code>class Comment &lt; ActiveRecord::Base
    belongs_to :post
    belongs_to :user
  
    default_scope { order('created_at DESC') }
  
    validates :body, length: { minimum: 5 }, presence: true
  
    after_create :send_favorite_emails
  
    private
  
    def send_favorite_emails
      self.post.favorites.each do |favorite|
        if favorite.user_id != self.user_id &amp;&amp; favorite.user.email_favorites?
          FavoriteMailer.new_comment(favorite.user, self.post, self).deliver
        end
      end
    end
  end
  </code></pre>
  
  <p>User model</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :trackable, :validatable, :confirmable
  
    has_many :posts
    has_many :comments
    has_many :votes, dependent: :destroy
    has_many :favorites, dependent: :destroy
    mount_uploader :avatar, AvatarUploader
  
    def role?(base_role)
      role == base_role.to_s
    end
  
    def favorited(post)
      self.favorites.where(post_id: post.id).first
    end
  
    def voted(post)
      self.votes.where(post_id: post.id).first
    end
  
    private
  end
  </code></pre>