Sha256: 0494dc5530002e5c4f65f36541bed802538da8a594e78cd6688e66c42a6519ff
Contents?: true
Size: 1.31 KB
Versions: 5
Compression:
Stored size: 1.31 KB
Contents
# -*- encoding : utf-8 -*- class RademadeAdmin::FileController < RademadeAdmin::AbstractController def upload param_key = params[:column].to_sym uploader.store!(params[param_key]) render :json => { :html => RademadeAdmin::Upload::PreviewService.new(uploader).preview_html, :file => uploader } rescue CarrierWave::UploadError => e show_error(e) end def download # todo filename send_file(uploader.model.send(uploader.mounted_as).file.file) end def crop image = uploader.crop_image(params[:crop], params[:path]) uploader.store!(image) upload_preview_service = RademadeAdmin::Upload::PreviewService.new(uploader) render :json => { :html => upload_preview_service.preview_html, :file => uploader } rescue CarrierWave::UploadError => e show_error(e) end private def show_error(error) render :json => { :error => error.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]) model_object = nil if params[:id].present? model_object = model_class.find(params[:id]) rescue nil end model_object || model_class.new end end
Version data entries
5 entries across 5 versions & 1 rubygems