Sha256: 7c14de076b9d0ff68ef823a3d82c681a8e571c6c27c1ea800abb58526e762255

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module RailsDevtools
  class ImageAssetsController < BaseController
    def show
      image_info = ImageAssets::ImageInfo.new(params[:image_path])
      render ImageAssets::ImageDetails.new(image_info: image_info)
    end

    def index
      form = ImageSearchForm.new(search: form_params[:search])
      render ImageAssets::Index.new(images_by_folder: form.results, form: form)
    end

    def destroy
      image_info = ImageAssets::ImageInfo.new(params[:image_path])
      raise "This is a not an image" unless image_info.valid?

      File.delete(image_info.full_path)

      respond_to do |format|
        format.html { redirect_to image_assets_path, notice: "Image was successfully destroyed." }
        format.turbo_stream {
          render turbo_stream: [
            turbo_stream.remove(image_info.full_path),
            turbo_stream.append(
              "flash_messages",
              Components::FlashMessage.new(
                message: "Image was successfully destroyed."
              )
            )
          ]
        }
      end
    end

    private

    def form_params
      params[:image_search_form] || { search: "" }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rails_devtools-0.1.3 app/controllers/rails_devtools/image_assets_controller.rb
rails_devtools-0.1.2 app/controllers/rails_devtools/image_assets_controller.rb
rails_devtools-0.1.1 app/controllers/rails_devtools/image_assets_controller.rb
rails_devtools-0.1.0 app/controllers/rails_devtools/image_assets_controller.rb