title: Getting undefined method 'parent'
body: <p>So i asked this question a while back before but i still cant seem to get this right . im trying to make my comment model make comments for both topics and posts. i just want Comments controller to be able to handle comments going to post or topic. </p>
  
  <p>routes :   </p>
  
  <pre><code>resources :topics, :posts do
       resources :comments, only: [:create, :destroy]
    end
  </code></pre>
  
  <p>Topic Model:</p>
  
  <pre><code>  has_many :comments, dependent: :destroy
  </code></pre>
  
  <p>Comment Model: </p>
  
  <pre><code>  belongs_to :post
    belongs_to :topic
  </code></pre>
  
  <p>Post: </p>
  
  <pre><code>  has_many :comments, dependent: :destroy
  </code></pre>
  
  <p>Comments Controller :</p>
  
  <pre><code>def create
  
      if params[:post_id]
        @parent = Post.find(params[:post_id])
        @comment = @parent.comments.new(comment_params)
        @comment.user = current_user
  
        if @comment.save
          flash[:notice] = "Comment saved successfully."
          redirect_to [@parent.topic, @parent]
        else
          flash[:alert] = "Comment failed to save."
          redirect_to [@parent.topic, @parent]
        end
      elsif params[:topic_id]
        @parent = Topic.find(params[:topic_id])
        @comment = @parent.comments.new(comment_params)
        @comment.user = current_user
  
        if @comment.save
          flash[:notice] = "Comment saved successfully."
        else
          flash[:alert] = "Comment failed to save."
        end
      end
    end
  
    def comment_params
      params.require(:comment).permit(:body)
    end
  </code></pre>
  
  <p>comment/form.html </p>
  
  <pre><code>&lt;%= form_for [@parent, @comment] do |f| %&gt;
    &lt;div class="form-group"&gt;
      &lt;%= f.label :body, class: 'sr-only' %&gt;
      &lt;%= f.text_field :body, class: 'form-control', placeholder: "Enter a new comment" %&gt;
    &lt;/div&gt;
    &lt;%= f.submit "Submit Comment", class: 'btn btn-default pull-right' %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>I keep getting <code>undefined local variable or method parent</code> when trying to go to my topic/show view
  also how can i implement comments to show up on topic/post view </p>