CKEditor二进制载波 [英] CKEditor Carrierwave Cloudinary
问题描述
我想让CKEditor使用Carrierwave和Cloudinary。到目前为止,非CKEditor启用的视图与常规文件上传字段与Carrierwave&二进制。但是,当我尝试上传一个文件CKEditor和发送到服务器我得到一个 NoMethodError - 未定义的方法'each'forimage / jpeg:String:
在从CKEditor类中删除本地存储配置之前,它是工作,但在本地保存文件。
这是我目前的CKEditor上传器:
class CkeditorAttachmentFileUploader< CarrierWave :: Uploader :: Base
include Cloudinary :: CarrierWave
包括Ckeditor :: Backend :: CarrierWave
def extension_white_list
Ckeditor.attachment_file_types
end
end
日志文件:
< pre> at 2013-06-20 15:44:18 -0700
Ckeditor处理:: PicturesController#create as html
参数:{upload=>#< ActionDispatch :: Http :: UploadedFile :0x007ff742c77018 @ original_filename =pic1.jpg,@ content_type =image / jpeg,@ headers =Content-Disposition:form-data; name = \upload\;; filename = \pic1.jpg \\ r\\\
Content-Type:image / jpeg \r\\\
,@tempfile =#< Tempfile:/ var / folders / 0t / l1qc3j596v77_z3s8f2pm75w0000gn / T / RackMultipart20130620-18566-i0av53> ,CKEditor=>subsection_content,CKEditorFuncNum=>3,langCode="en,authenticity_token=>5Bt06UwjUD / EdLFANBmZojdv8Hvn2GbQRLvC6h11Dd8 =}
ms)BEGIN
(0.4ms)ROLLBACK
完成500内部服务器错误4ms
NoMethodError - 未定义的方法`each'forimage / jpeg:String:
(gem)cloudinary-1.0.59 / lib / cloudinary / carrier_wave / process.rb:100:in'block in transformation'
任何想法赞赏!
UPDATE - 从Tal Lev-Ami回答工作配置 b
这是我目前的工作 ckeditor_picture_uploader.rb
档案:
#encoding:utf-8
尝试将以下代码添加到您的CkPictureUploader / CkeditorAttachmentFileUploader: pre>
class CkeditorPictureUploader< CarrierWave :: Uploader :: Base
包括Ckeditor :: Backend :: CarrierWave
包括Cloudinary :: CarrierWave
#包括RMagick或ImageScience支持:
#包括CarrierWave :: RMagick
包括CarrierWave :: MiniMagick
#include CarrierWave :: ImageScience
#选择用于此上传器的存储类型:
#storage:file
#覆盖存储上传文件的目录。
#这是一个明智的默认值为上传者打算挂载:
#def store_dir
#uploads / ckeditor / pictures /#{model.id}
# end
#如果没有上传文件,请提供默认URL:
#def default_url
#/ images / fallback /+ [version_name, default.png]。compact.join('_')
#end
#在上传文件时处理文件:
#process:scale => [200,300]
#
#def scale(width,height)
##做某事
#end
[:extract_content_type,:set_size ,:read_dimensions] .each do | method |
define_method:#{method} _with_cloudinarydo
send(:#{method} _without_cloudinary)if self.file.is_a?(CarrierWave :: SanitizedFile)
{}
end
alias_method_chain method,:cloudinary
end
过程:read_dimensions
#创建不同版本的上传文件:
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
<[:extract_content_type,:set_size,:read_dimensions] .each do | method |
define_method:#{method} _with_cloudinarydo
send(:#{method} _without_cloudinary)if self.file.is_a?(CarrierWave :: SanitizedFile)
{}
end
alias_method_chain method,:cloudinary
end
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 Carrierwave & Cloudinary. However, when I try to upload a file in CKEditor and "Send it to the Server" I'm getting a
NoMethodError - undefined method 'each' for "image/jpeg":String:
Prior to removing the local storage config from the CKEditor classes it was working, but saving the file locally.
Here is my current CKEditor uploader:
class CkeditorAttachmentFileUploader < CarrierWave::Uploader::Base include Cloudinary::CarrierWave include Ckeditor::Backend::CarrierWave def extension_white_list Ckeditor.attachment_file_types end end
Log file:
Started POST "/ckeditor/pictures?CKEditor=subsection_content&CKEditorFuncNum=3&langCode=en&authenticity_token=5Bt06UwjUD%2FEdLFANBmZojdv8Hvn2GbQRLvC6h11Dd8%3D" for 127.0.0.1 at 2013-06-20 15:44:18 -0700 Processing by Ckeditor::PicturesController#create as HTML Parameters: {"upload"=>#<ActionDispatch::Http::UploadedFile:0x007ff742c77018 @original_filename="pic1.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"upload\"; filename=\"pic1.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<Tempfile:/var/folders/0t/l1qc3j596v77_z3s8f2pm75w0000gn/T/RackMultipart20130620-18566-i0av53>>, "CKEditor"=>"subsection_content", "CKEditorFuncNum"=>"3", "langCode"=>"en", "authenticity_token"=>"5Bt06UwjUD/EdLFANBmZojdv8Hvn2GbQRLvC6h11Dd8="} (0.4ms) BEGIN (0.4ms) ROLLBACK Completed 500 Internal Server Error in 4ms NoMethodError - undefined method `each' for "image/jpeg":String: (gem) cloudinary-1.0.59/lib/cloudinary/carrier_wave/process.rb:100:in `block in transformation'
Any ideas appreciated!
UPDATE - Working config from Tal Lev-Ami answer
This is my current, working
ckeditor_picture_uploader.rb
file:# encoding: utf-8 class CkeditorPictureUploader < CarrierWave::Uploader::Base include Ckeditor::Backend::CarrierWave include Cloudinary::CarrierWave # Include RMagick or ImageScience support: # include CarrierWave::RMagick include CarrierWave::MiniMagick # include CarrierWave::ImageScience # Choose what kind of storage to use for this uploader: # storage :file # Override the directory where uploaded files will be stored. # This is a sensible default for uploaders that are meant to be mounted: # def store_dir # "uploads/ckeditor/pictures/#{model.id}" # end # Provide a default URL as a default if there hasn't been a file uploaded: # def default_url # "/images/fallback/" + [version_name, "default.png"].compact.join('_') # end # Process files as they are uploaded: # process :scale => [200, 300] # # def scale(width, height) # # do something # end [: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
解决方案Try to add the following code to your CkPictureUploader/CkeditorAttachmentFileUploader:
[: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
这篇关于CKEditor二进制载波的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!