title: How to only let the author of comments edit, update & destroy them?
body: <p>I'm trying to prevent all users being able to edit, update and destroy comments made to posts in my forum. I managed to prevent all users editing the posts, but i can't work out what i need to do to prevent all users editing the comments.</p>
  
  <p>I solved the post issue with this before_action in the post controller:</p>
  
  <pre><code>before_action :post_owner, only: [:edit, :update, :destroy]
  </code></pre>
  
  <p>This is my show.html.haml:</p>
  
  <pre><code>#post_content
  
  %h1= @post.title
  %p= @post.content
  
  #comments
      %h2
          = @post.comments.count
          Comments
      = render @post.comments
  
      - if user_signed_in?
  
          %h3 Reply to thread
          = render'comments/form'
  
          %br/
          %hr/
          %br
  
          - if @post.user_id == current_user.id
              = link_to "Edit", edit_post_path(@post), class: "button"
              = link_to "Delete", post_path(@post), method: :delete, data: { confirm: "Are you sure you want to do this?"}, class: "button"
  </code></pre>
  
  <p>I added a before_action for comments in the post_controller and tried this in the _comment.html.haml:</p>
  
  <pre><code>.comment.clearfix
  .content
      %p.comment_content= comment.comment
      %p.comment_author= comment.user.email
  
  %br/
  %br/
  %br/
  %br/
  
  - if @comment.user_id == current_user.id
  
      = link_to "Edit", edit_post_comment_path(comment.post, comment), class: "button"
  
      = link_to "Delete", [comment.post, comment], method: :delete, data: { confirm: "Are you sure?"}, class: "button"
  </code></pre>
  
  <p>However i receive the following error:</p>
  
  <pre><code>undefined method `user_id' for nil:NilClass
  </code></pre>
  
  <p>I think this is a simple solution but i'm not that experienced with ruby on rails just yet.</p>