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
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.
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
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
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