unused image finder

This commit is contained in:
2023-01-23 14:53:04 +02:00
parent dd0a0d0ced
commit 1570e34d35
2 changed files with 22 additions and 7 deletions

View File

@ -5,7 +5,7 @@ module Merged
before_action :set_image, only: %i[ update destroy show scale crop copy ]
def index
@images = Image.all
@images = get_images
@image_data = @images.collect{|i|
data = i.attributes.dup
data[:url] = view_context.asset_path(i.asset_name)
@ -65,6 +65,18 @@ module Merged
private
def get_images
images = Image.all
puts "Images #{images.length}"
return images unless params[:unused]
hash = images.collect{|i| [i.id , i ] }.to_h
puts "Images1 #{hash.length}"
Section.all.each{ |s| hash.delete(s.image&.id)}
puts "Images2 #{hash.length}"
Card.all.each{ |s| hash.delete(s.image&.id)}
puts "Images3 #{hash.length}"
hash.values
end
def set_image
@image = Image.find(params[:id] || params[:image_id])
end