From 604fede5a780832c334881dc603c685d2f34162e Mon Sep 17 00:00:00 2001 From: Adrian Hinz Date: Mon, 23 Apr 2018 08:19:50 +0200 Subject: [PATCH] fix for image destroy --- app/controllers/ps_admin/image_controller.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/ps_admin/image_controller.rb b/app/controllers/ps_admin/image_controller.rb index db42e86..894f044 100644 --- a/app/controllers/ps_admin/image_controller.rb +++ b/app/controllers/ps_admin/image_controller.rb @@ -80,9 +80,13 @@ module PsAdmin image = Image.where(id: params[:id]).first unless image.blank? if image.cover.eql?(true) - img = Image.where('imageable_type = ? AND imageable_id = ? AND id != ?', image.imageable_type, image.imageable_id, image.id).first - img.cover = true - img.save + img = Image.by_image_type(image.imageable_type) + .where('imageable_id = ? AND id != ?', + image.imageable_id, image.id).first + unless img.blank? + img.cover = true + img.save + end end image.destroy end