favoritescontroller#destroy should work even if the post doesn't exist, remove from favorites on expunge (fixes #3222)

This commit is contained in:
r888888888
2017-07-19 13:22:24 -07:00
parent 5d013f9c88
commit d48ed95191
7 changed files with 50 additions and 21 deletions

View File

@@ -47,12 +47,19 @@ class FavoritesController < ApplicationController
end
def destroy
@post = Post.find(params[:id])
@post.remove_favorite!(CurrentUser.user)
@post = Post.find_by_id(params[:id])
if @post
@post.remove_favorite!(CurrentUser.user)
path = mobile_post_path(@post)
else
Favorite.remove(post_id: params[:id], user: CurrentUser.user)
path = mobile_posts_path
end
respond_with(@post) do |format|
format.html do
redirect_to(mobile_post_path(@post))
redirect_to(path)
end
format.js
format.json do