title: Find votes by current user on a post
body: <p>i'm building an application where users can submit posts and vote on them.</p>
  
  <p>I need to find a way to allow users to delete their vote.</p>
  
  <p>I started a private method called <code>correct_user</code> under my <code>votes_controller</code>, but I don't quite know how to pull the current user's vote id to a specific post. I figure once I have the ID I can pass it through to an instance variable where I can call the <code>vote_path(@vote), method: :delete</code> on it.</p>
  
  <p>However, right now I don't quite know how to pull the proper id for a vote by a specific user on a specific post.</p>
  
  <p>I did <code>@vote = current_user.votes.find_by_id(params[:id])</code> in my <code>current user</code> method, but obviously that's not working. Not really sure how to pull this off. Any help would be great.</p>
  
  <p>votes_controller.rb:</p>
  
  <pre><code>before_filter :correct_user, only: [:destroy]
  
  def destroy
    @vote.destroy
    flash[:notice] = "Your vote has been deleted"
    redirect_to root_path
  end
  
  private
  
  def vote_params
    params.require(:vote).permit(:user_id, :post_id, :up)
  end
  
  def correct_user
    @vote = current_user.votes.find_by_id(vote_params[:post_id)
    redirect_to root_path if @vote.nil?
  end
  </code></pre>
  
  <p>and from my views:</p>
  
  <pre><code>&lt;%= link_to "delete", vote_path(@vote), method: :delete %&gt;
  </code></pre>