Sha256: b3ad3c95458f7ff54613496795724055ddc9c56e7ba19c34b45ff699442e3e79

Contents?: true

Size: 799 Bytes

Versions: 1

Compression:

Stored size: 799 Bytes

Contents

# -*- encoding : utf-8 -*-
class RademadeAdmin::FileController < RademadeAdmin::AbstractController

  def upload
    param_key = params[:column].to_sym
    uploader.store!(params[param_key])
    upload_preview_service = RademadeAdmin::Upload::PreviewService.new(uploader)
    render :json => {
      :html => upload_preview_service.preview_html,
      :file => uploader
    }
  rescue CarrierWave::UploadError => e
    render :json => { :error => e.to_s }, :status => :unprocessable_entity
  end

  def uploader
    @uploader ||= RademadeAdmin::LoaderService.const_get(params[:uploader]).new(model, params[:column])
  end

  def model
    model_class = RademadeAdmin::LoaderService.const_get(params[:model])
    params[:saved].to_i.zero? ? model_class.new : model_class.find(params[:id])
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rademade_admin-0.1.0 app/controllers/rademade_admin/file_controller.rb