app/controllers/spina/admin/images_controller.rb
def create
        @images = params[:image][:files].map do |file|
          next if file.blank? # Skip the blank string posted by the hidden files[] field
          
          # Create the image and attach the file
          image = Image.create(media_folder_id: image_params[:media_folder_id])
          image.file.attach(file)

          # Was it not an image after all? DESTROY IT
          image.destroy and next unless image.file.image?

          image
        end.compact
        
        if params[:modal]
          redirect_to spina.admin_media_picker_path(media_folder_id: image_params[:media_folder_id])
        else
          render turbo_stream: turbo_stream.prepend("images", partial: "image", collection: @images)
        end
      end
# There's no file validation yet in ActiveStorage
# We do two things to reduce errors right now:
# 1. We add accept="image/*" to the image form
# 2. We destroy the entire record if the uploaded file is not an image
There's no file validation yet in ActiveStorage
We do two things to reduce errors right now:
1. We add accept="image" to the image form
2. We destroy the entire record if the uploaded file is not an image
There ' s no file validation yet in ActiveStorage We do two things to reduce errors right now : 1 . We add accept = " image " to the image form 2 . We destroy the entire record if the uploaded file is not an image
def create
        @images = params[:image][:files].map do |file|
          next if file.blank? 
          image = Image.create(media_folder_id: image_params[:media_folder_id])
          image.file.attach(file)
          image.destroy and next unless image.file.image?
          image
        end.compact
        if params[:modal]
          redirect_to spina.admin_media_picker_path(media_folder_id: image_params[:media_folder_id])
        else
          render turbo_stream: turbo_stream.prepend("images", partial: "image", collection: @images)
        end
      end
def create @images = params [ :image ] [ :files ] . map do | file | next if file . blank? image = Image . create ( media_folder_id : image_params [ :media_folder_id ] ) image . file . attach ( file ) image . destroy and next unless image . file . image? image end . compact if params [ :modal ] redirect_to spina . admin_media_picker_path ( media_folder_id : image_params [ :media_folder_id ] ) else render turbo_stream : turbo_stream . prepend ( "images" , partial : "image" , collection : @images ) end end
There's no file validation yet in ActiveStorage
We do two things to reduce errors right now:
1.
There ' s no file validation yet in ActiveStorage We do two things to reduce errors right now : 1 .
# Skip the blank string posted by the hidden files[] field # Create the image and attach the file # Was it not an image after all? DESTROY IT