From 3cd57afdd5ba8b999dc8e2285a94fa7520c1e8c8 Mon Sep 17 00:00:00 2001 From: Anton Holovko Date: Thu, 10 May 2018 16:42:16 +0300 Subject: [PATCH] add redactor3 compatibility --- app/controller/redactor2_rails/files_controller.rb | 2 +- app/controller/redactor2_rails/images_controller.rb | 2 +- lib/generators/redactor2/templates/config.js | 8 ++++++-- lib/redactor2_rails/http.rb | 4 +++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controller/redactor2_rails/files_controller.rb b/app/controller/redactor2_rails/files_controller.rb index aaa1b09..44ff889 100755 --- a/app/controller/redactor2_rails/files_controller.rb +++ b/app/controller/redactor2_rails/files_controller.rb @@ -12,7 +12,7 @@ def create end if @file.save - render json: { url: @file.url, name: @file.filename } + render json: { file: { url: @file.url, name: @file.filename } } else render json: { error: @file.errors } end diff --git a/app/controller/redactor2_rails/images_controller.rb b/app/controller/redactor2_rails/images_controller.rb index 83db4de..a89102a 100755 --- a/app/controller/redactor2_rails/images_controller.rb +++ b/app/controller/redactor2_rails/images_controller.rb @@ -12,7 +12,7 @@ def create end if @image.save - render json: { id: @image.id, url: @image.url(:content) } + render json: { file: { id: @image.id, url: @image.url(:content) } } else render json: { error: @image.errors } end diff --git a/lib/generators/redactor2/templates/config.js b/lib/generators/redactor2/templates/config.js index f531627..9922e09 100755 --- a/lib/generators/redactor2/templates/config.js +++ b/lib/generators/redactor2/templates/config.js @@ -5,9 +5,13 @@ $(function () { $.Redactor.settings = { //plugins: ['source', 'fullscreen', 'textdirection', 'clips'], imageUpload: '/redactor2_rails/images', - imageUploadFields: params, + imageData: { + elements: params + }, fileUpload: '/redactor2_rails/files', - fileUploadFields: params + fileData: { + elements: params + }, }; // Initialize Redactor $('.redactor').redactor(); diff --git a/lib/redactor2_rails/http.rb b/lib/redactor2_rails/http.rb index a46384e..c482684 100755 --- a/lib/redactor2_rails/http.rb +++ b/lib/redactor2_rails/http.rb @@ -77,8 +77,10 @@ def body # file upload hash with UploadedFile objects def self.normalize_param(*args) value = args.first - if Hash === value && value.has_key?(:tempfile) + if Hash == value && value.has_key?(:tempfile) UploadedFile.new(value) + elsif value.is_a?(Array) + value.first elsif value.is_a?(String) QqFile.new(*args) else