CKEditor Carrierwave Cloudinary

前端 未结 4 1779
星月不相逢
星月不相逢 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.

    0 讨论(0)
  • 2021-01-06 11:18

    Checkout my comment here

    https://github.com/galetahub/ckeditor/issues/670#issuecomment-301218366

    # encoding: utf-8
    class CkeditorPictureUploader < CarrierWave::Uploader::Base
      include Ckeditor::Backend::CarrierWave
      include CarrierWave::MiniMagick
      include Cloudinary::CarrierWave
    
      process :extract_dimensions
    
      [: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_chain method, :cloudinary
      end
    
      version :thumb do
        process :resize_to_fill => [118, 100]
      end
    
      version :content do
        process :resize_to_limit => [800, 800]
      end
    
      def extension_white_list
        Ckeditor.image_file_types
      end
    end
    
    0 讨论(0)
  • 2021-01-06 11:26

    Try to add the following code to your CkPictureUploader/CkeditorAttachmentFileUploader:

    [: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_chain method, :cloudinary
    end
    
    0 讨论(0)
  • 2021-01-06 11:33

    Ckeditor was updated so this may need to be extract_size and extract_dimensions depending on ckeditor gem version

    Commit Where it was changed: https://github.com/galetahub/ckeditor/blob/4e6d8413cc71f40d2d58ab3d0cb8dad19dd96894/lib/ckeditor/backend/carrierwave.rb

    ie:

    [: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_chain method, :cloudinary
    end
    
    0 讨论(0)
提交回复
热议问题