CKEditor Carrierwave Cloudinary

前端 未结 4 1809
星月不相逢
星月不相逢 2021-01-06 10:52

I\'m trying to get CKEditor to work with Carrierwave and Cloudinary. So far, non-CKEditor enabled views with a regular file upload field are working perfectly with Carrierwa

4条回答
  •  清歌不尽
    2021-01-06 11:14

    I also have issue with the combination of these gems. Edit your CkeditorAttachmentFileUploader to look similar to this:

    class CkeditorAttachmentFileUploader < CarrierWave::Uploader::Base
      include Ckeditor::Backend::CarrierWave
      include Cloudinary::CarrierWave
    
      [:extract_content_type, :extract_size, :extract_dimensions].each do |method|
        define_method :"#{method}_with_cloudinary" do
          send(:"#{method}_without_cloudinary") if self.file.is_a?(CarrierWave::SanitizedFile)
          {}
        end
        alias_method :"#{method}_without_cloudinary", method
        alias_method method, :"#{method}_with_cloudinary"
      end
    
      def extension_white_list
        Ckeditor.attachment_file_types
      end
    end
    

    After that, you will find another error. I found that in Ckeditor::AssetResponse#asset_url method, the asset object is not reloaded, so asset.content_url will always be nil thus caused the error. I fixed it like this:

    class Ckeditor::Picture < Ckeditor::Asset
      ...
      def url_content
        url(:content) || begin
          if persisted?
            reload
            url(:content)
          end
        end
      end
    end
    

    And similarly for Ckeditor::AttachmentFile class if you have it.

提交回复
热议问题