title: Rails: ActionController::InvalidAuthenticityToken
body: <p>I'm currently working on a project involving users, likes, and posts. I have a like/unlike button that I finally got to work some of the time, but on certain user's profiles when I go to unlike a post, I get thrown this error, which says that it is coming from my destroy action in my likes controller:</p>
  
  <pre><code>ActionController::InvalidAuthenticityToken
  </code></pre>
  
  <p>I'm using devise, but don't know if that has to do with the cause of the issue.</p>
  
  <p>Right now this is what I'm working with:</p>
  
  <pre><code>&lt;h4&gt;All of &lt;%= @user.email %&gt;'s posts:&lt;/h4&gt;
  &lt;% @user.posts.order('created_at DESC').each do |post| %&gt;
      &lt;li&gt;&lt;%= post.content %&gt;&lt;/li&gt;
  &lt;% unless current_user.likes.pluck(:post_id).include?(post.id) %&gt;
  &lt;%= form_tag likes_path do %&gt;
    &lt;%= hidden_field_tag 'post_id', post.id %&gt;
    &lt;%= submit_tag "Like", :class =&gt; "like_button" %&gt;
  &lt;% end %&gt;
  &lt;% else %&gt;
  &lt;% like = post.likes.where(user_id: current_user.id).first %&gt;
  &lt;div class="unlike_button"&gt;
      &lt;%= form_tag like_path(like) do %&gt;
    &lt;%= hidden_field_tag 'post_id', post.id %&gt;
  
    &lt;%= button_to "Unlike", like_path(post), method: :delete %&gt;
  &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
    
      
  
  <hr>
  
  <pre><code>class LikesController &lt; ApplicationController
  def create
  @post = Post.find(params[:post_id])
  
  @like = Like.new(user_id: current_user.id, post_id: @post.id)
  if @like.save
      flash[:success] = "Post Liked!"
      redirect_back(fallback_location: root_path)
  else
      flash[:notice] = "Couldn't like post"
      redirect_back(fallback_location: root_path)
  end
  end
  
  
  def destroy
    @like = Like.find(params[:id])
    @like.destroy
    flash[:success] = "Post unliked"
    redirect_back(fallback_location: root_path)
  end
  </code></pre>
  
  <h2>    end</h2>
  
  <pre><code>     class PostsController &lt; ApplicationController
  
  def index
      @posts = Post.all
      @user = User.find(params[:user_id])
  end
  
  def new
      @post = Post.new
      @user = User.find(params[:user_id])
  end
  
  def create
      @post = current_user.posts.build(post_params)
      if @post.save
          flash[:success] = "Posted!"
          redirect_to user_path(current_user)
      else
          flash[:notice] = "Post could not be submitted"
          redirect_to users_path
      end
  end
  
  private
  
  def post_params
      params.require(:post).permit(:content)
  end
  end 
  </code></pre>