title: I am novice, writing an app similar to Reddit, and the error I get is: undefined method `user' for #<Topic
body: <pre><code>NoMethodError in Topics#show
  </code></pre>
  
  <blockquote>
    <blockquote>
      <p>Showing /Users/Tish/code/bloccit/app/views/topics/show.html.erb where line #37 raised:</p>
      
      <blockquote>
        <p>undefined method `user' for #
        Extracted source (around line #37):</p>
      </blockquote>
    </blockquote>
  </blockquote>
  
  <pre><code>34  &lt;%= link_to "New Post", new_topic_post_path(@topic), class: 'btn btn-success' %&gt;  
  35  &lt;% end %&gt;
  36
  37  &lt;% if policy(@topic).destroy? %&gt;
  38  &lt;%= link_to "Delete Topic", @topic, method: :delete, class: 'btn btn-     danger', 
           data: { confirm: 'Are you sure you want to delete this topic?' } %&gt; 
           &lt;% end %&gt;
  </code></pre>
  
  <blockquote>
    <p>here is schema.rb: </p>
  </blockquote>
  
  <pre><code>ActiveRecord::Schema.define(version: 20150128034556) do
  
    create_table "comments", force: true do |t|
  t.text     "body"
  t.integer  "post_id"
  t.datetime "created_at"
  t.datetime "updated_at"
  t.integer  "user_id"
    end
  
    add_index "comments", ["post_id"], name: "index_comments_on_post_id"
    add_index "comments", ["user_id"], name: "index_comments_on_user_id"
  </code></pre>
  
  <blockquote>
    <p>model/user.rb:</p>
  </blockquote>
  
  <pre><code>class User &lt; ActiveRecord::Base
    devise :database_authenticatable, :registerable,
       :recoverable, :rememberable, :trackable, :validatable, :confirmable
  
    has_many :posts
    has_many :comments 
  
    mount_uploader :avatar, AvatarUploader
  
    def admin?
     role == 'admin'    
    end
  
   def moderator?
    role == 'moderator'
   end
  
  end
  </code></pre>
  
  <blockquote>
    <p>model/comment.rb</p>
  </blockquote>
  
  <pre><code>   class Comment &lt; ActiveRecord::Base
      belongs_to :post
      belongs_to :user
  
      default_scope -&gt; { order(created_at: :desc) }
  
  end  
  </code></pre>
  
  <blockquote>
    <p>The problem shows when I click on a topic, I get an error. Please excuse me ahead of time for not formatting the question correctly!</p>
    
    <p>here is one of the policies: </p>
  </blockquote>
  
  <pre><code>   class TopicPolicy &lt; ApplicationPolicy
  
     def index?
      true
     end
  
     def create?
      user.present? &amp;&amp; user.admin?
     end
  
     def update?
      create?
     end
  
     def destroy?
      user.present? &amp;&amp; can_moderate?(user, record)
     end
   end
  </code></pre>