微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby-on-rails – CKEditor Carrierwave Cloudinary

我想让CKEditor与Carrierwave和Cloudinary一起工作.到目前为止,具有常规文件上载字段的非CKEditor启用视图与Carrierwave& Cloudinary.但是,当我尝试在CKEditor中上传文件并“将其发送到服务器”时,我得到一个NoMethodError – 未定义的方法’each’代表“image / jpeg”:字符串:

在从CKEditor类中删除本地存储配置之前,它正在工作,但在本地保存文件.

这是我目前的CKEditor上传器:

class CkeditorAttachmentFileUploader < CarrierWave::Uploader::Base
  include Cloudinary::CarrierWave
  include Ckeditor::Backend::CarrierWave

  def extension_white_list
    Ckeditor.attachment_file_types
  end
end

日志文件

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'

任何想法赞赏!

更新 – Tal Lev-Ami的工作配置回答

这是我当前工作的ckeditor_picture_uploader.rb文件

# 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

解决方法

尝试将以下代码添加到您的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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐