favoritescontroller#destroy should work even if the post doesn't exist, remove from favorites on expunge (fixes #3222)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user