Sha256: d7a0670cff8bf40e94d8f1d8377a2fc089be67b551d9878ab286173c81eae93e

Contents?: true

Size: 1.38 KB

Versions: 12

Compression:

Stored size: 1.38 KB

Contents

class Adminsite::Admin::AdminsiteFileAssetsController < Adminsite::Admin::ResourcesController

  def index
    @file_asset = Adminsite::FileAsset.new
    super
  end

  def create
    success_files = []
    failure_files = []

    if params[:file_asset].present?
      Array(permitted_params[:file_asset][:attachment]).each do |file|
        filename = file.original_filename

        # "Overwrite" existing by removing them
        Adminsite::FileAsset.find_by_attachment_file_name(filename).try(:destroy)

        file_asset = Adminsite::FileAsset.new('attachment' => file)
        if file_asset.save!
          success_files << "'#{filename}'"
        else
          failure_files << "'#{filename}'"
        end
      end
    end

    flash[:notice] = "File(s) #{success_files.join(', ')} were successfully uploaded." if success_files.any?
    flash[:errors] = "File(s) #{failure_files.join(', ')} were not uploaded."          if failure_files.any?

    Adminsite::Page.cleanup_all_cached
    redirect_to admin_adminsite_file_assets_path
  end

  def destroy
    super
    Adminsite::Page.cleanup_all_cached
    # redirect_to admin_adminsite_file_assets_path
  end

  protected

  def order_params
    'attachment_file_name ASC'
  end

  def resource_admin_config
    # Adminsite::Admin::ResourcesController.resource_admin_config
    super
  end

  def self.resource_class
    Adminsite::FileAsset
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
adminsite-3.2.4 app/controllers/adminsite/admin/adminsite_file_assets_controller.rb
adminsite-3.2.3 app/controllers/adminsite/admin/adminsite_file_assets_controller.rb
adminsite-3.2.2 app/controllers/adminsite/admin/adminsite_file_assets_controller.rb
adminsite-3.2.1 app/controllers/adminsite/admin/adminsite_file_assets_controller.rb
adminsite-3.2.0 app/controllers/adminsite/admin/adminsite_file_assets_controller.rb
adminsite-3.1.2 app/controllers/adminsite/admin/adminsite_file_assets_controller.rb
adminsite-3.1.1 app/controllers/adminsite/admin/adminsite_file_assets_controller.rb
adminsite-3.1.0 app/controllers/adminsite/admin/adminsite_file_assets_controller.rb
adminsite-3.0.0 app/controllers/adminsite/admin/adminsite_file_assets_controller.rb
adminsite-2.1.2 app/controllers/adminsite/admin/adminsite_file_assets_controller.rb
adminsite-2.1.1 app/controllers/adminsite/admin/adminsite_file_assets_controller.rb
adminsite-2.1.0 app/controllers/adminsite/admin/adminsite_file_assets_controller.rb