title: undefined method `destroy' on Public Activity
body: <p>User's can comment on a Screen and it's tracked by PublicActivity :</p>
  
  <pre><code>@comment.create_activity :create, owner: current_user, recipient: @comment.screen.user
  </code></pre>
  
  <p>and the comments are dependent: :destroy on the screen model.</p>
  
  <p>But when i delete a screen, while the comments are deleted, the Record from PublicActivity for that comment still exists.</p>
  
  <p>here's my <code>Screens Controller</code>:</p>
  
  <pre><code>  def destroy
      @activity = PublicActivity::Activity.find_by_trackable_id(params[:id])
      @activity.destroy #&lt;-- Heres the Problem
      @screen.destroy
      respond_to do |format|
        format.html { redirect_to root_path }
        format.json { head :no_content }
      end
    end
  </code></pre>
  
  <p>But upon deleting a Screen, i'm getting <code>undefined method</code>destroy' for nil:NilClass`.</p>
  
  <p>I read on Railscast:</p>
  
  <blockquote>
    <p>it was due to calling the create_activity method after the object had
    been destroyed.</p>
    
    <p>According to the gem maintainers, you simply have to assume the record
    will be destroyed, and call create_activity before the destroy</p>
  </blockquote>
  
  <p>What am i missing?</p>
  
  <blockquote>
    <p><strong>Informations below</strong></p>
  </blockquote>
  
  <p>screen.rb</p>
  
  <pre><code>belongs_to :user
  has_many :comments, :dependent =&gt;  :destroy
  </code></pre>
  
  <p>comment.rb</p>
  
  <pre><code>belongs_to :user
  belongs_to :screen
  </code></pre>
  
  <p>screens_contoller.rb</p>
  
  <pre><code>  def create
      @screen = current_user.screens.build(screen_params)
      respond_to do |format|
        if @screen.save
           format.html { redirect_to @screen, notice: 'You successfully uploaded your Screenshot.' }
          format.json { render action: 'show', status: :created, location: @screen }
          current_user.add_points(2, 'Points for Uploading a Screenshot')
        else
          format.html { render action: 'new' }
          format.json { render json: @screen.errors, status: :unprocessable_entity }
        end
      end
    end
  
    def destroy
      @activity = PublicActivity::Activity.find_by_trackable_id(params[:id])
      @activity.destroy
      @screen.destroy
      respond_to do |format|
        format.html { redirect_to root_path }
        format.json { head :no_content }
        current_user.substract_points(1, "Substraction for Deleting a Screenshot")
      end
    end
  </code></pre>
  
  <p>comments_controller.rb</p>
  
  <pre><code>  def create
      @screen = Screen.find(params[:screen_id])
      @comment = current_user.comments.build(comment_params)
      @comment.screen_id = @screen.id
      respond_to do |format|
        if @comment.save
          # Create Record for Public Activity
          @comment.create_activity :create, owner: current_user, recipient: @comment.screen.user
          format.html { redirect_to @screen, notice: 'Comment was successfully created.' }
          format.json { render action: 'show', status: :created, location: @comment }
        else
          format.html { render action: 'new' }
          format.json { render json: @comment.errors, status: :unprocessable_entity }
        end
      end
    end
  
    def destroy
      @comment.destroy
      respond_to do |format|
        @activity = PublicActivity::Activity.find_by_trackable_id(params[:id])
        @activity.destroy
        format.html { redirect_to :back }
        format.json { head :no_content }
      end
    end
  </code></pre>
  
  <p><strong>That's how my Screen Controller Destroy Action looks like right now:</strong></p>
  
  <pre><code>  def destroy
      @screen = current_user.screens.find(params[:id])
      @activity = PublicActivity::Activity.find_by_trackable_id(params[:id])
      @activity.destroy
      @screen.destroy
      current_user.substract_points(1, "Substraction for Deleting a Screenshot")
      respond_to do |format|
        format.html { redirect_to root_path }
      end
    end
  </code></pre>
  
  <p>Again the same error:</p>
  
  <p><img src="https://i.stack.imgur.com/OOBCe.png" alt="enter image description here"></p>