我在rails 4中有一个使用带有cloudinary的ckeditor的项目 . Cloudinary的上传工作正常,但上传后,当编辑器应该播放图像时,我收到错误:
NoMethodError - undefined method `gsub' for nil:NilClass:
我的CKEditor图片上传器是:
# encoding: utf-8
class CkeditorPictureUploader < CarrierWave::Uploader::Base
include Ckeditor::Backend::CarrierWave
include Cloudinary::CarrierWave
include CarrierWave::MiniMagick
[:extract_content_type, :set_size, :read_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
process :read_dimensions
# Create different versions of your uploaded files:
version :thumb do
process :resize_to_fill => [118, 100]
end
version :content do
process :resize_to_limit => [800, 800]
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
Ckeditor.image_file_types
end
end
当我上传并点击“在服务器上查找图像”时,图像就在那里我可以在编辑器上加载图像,但是当我将图像上传到服务器时却没有
有人之前遇到过这个问题吗?
谢谢!
2 回答
发生此错误是因为
gsub
无法在ckeditor中找到上传图像的网址 . 你必须在你的应用程序的lib / ckeditor文件夹中创建ckeditor asset_response.rb文件并放入这行代码放入整个代码并用此替换asset_url方法 . 这只是一个包含
Ckeditor::Picture
模型的黑客 .在CkeditorPictureUploader文件中将此代码用于cloudinary
从@ t-s的回答中,我发现在Ckeditor::AssetResponse#asset_url方法中,
asset
对象没有重新加载,因此asset.content_url
将始终为nil,从而导致错误 . 我这样修好了:对于
Ckeditor::AttachmentFile
类,如果你有它,同样如此 .