轨道 3.2.13 关联销毁。列出已销毁但未移除图像文件的图像记录



我有一个User模型、listing模型和listing_images模型。

用户型号:

has_many :listings, dependent: :destroy
has_many :listing_images, through: listings

上市模式:

has_many :listing_images, dependent: :destroy
belongs_to :user

Listing_image:

belongs_to :listing
belongs_to :user    

当用户删除他们的列表时,我还想删除与该列表相关联的图像。当对列表调用destroy时,listing_images记录将从数据库中删除,但文件仍在那里。

作为测试,我删除了一个用户,看看它是否会删除配置文件图像,这很好。

我是不是错过了什么?

listing_image模型中:

before_destroy :remove_image_file
def remove_image_file
  # put logic here to get image path from db record and remove image file
end

最新更新