2016-09-05 59 views
0

我只是在ckeditor上做了圖片上傳,包括carrierwave和cloudinary 我試了一次,效果很好,我可以在我的筆記本上瀏覽圖片並通過ckeditor中的圖片上傳器上傳到cloudinary。但是當我嘗試編輯或創建新文章並嘗試上傳圖片時,圖片上傳程序不再有效。我不知道爲什麼,在成功完成圖像上傳之後,我沒有編輯任何內容。任何人都可以幫助我? THX反正RAILS 5:在上傳圖片後瀏覽服務器CKEditor錯誤'undefined method'path''

說出來這樣的 enter image description here

錯誤,這裏是我的模型/ CKEditor的/ asset.rb

class Ckeditor::Asset < ActiveRecord::Base 

    include Ckeditor::Orm::ActiveRecord::AssetBase 
    delegate :url, :current_path, :content_type, to: :data 
    validates :data, presence: true 
end 

模型/ CKEditor的/ picture.rb

class Ckeditor::Picture < Ckeditor::Asset 
    mount_uploader :data, CkeditorPictureUploader, mount_on: :data_file_name 

    def url_content 
    url(:content) 
    end 
end 

模型/ ckeditor/attachment_file.rb

class Ckeditor::AttachmentFile < Ckeditor::Asset 
    mount_uploader :data, CkeditorAttachmentFileUploader, mount_on: :data_file_name 

    def url_thumb 
    @url_thumb ||= Ckeditor::Utils.filethumb(filename) 
    end 
end 

上傳/ CKEditor的/ ckeditor_picture_uploader.rb

class CkeditorPictureUploader < CarrierWave::Uploader::Base 
    include Ckeditor::Backend::CarrierWave 
    include Cloudinary::CarrierWave 
    include CarrierWave::MiniMagick 

    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 

配置/初始化/ ckeditor.rb

Ckeditor.setup do |config| 
    # ==> ORM configuration 
    # Load and configure the ORM. Supports :active_record (default), :mongo_mapper and 
    # :mongoid (bson_ext recommended) by default. Other ORMs may be 
    # available as additional gems. 
    require "ckeditor/orm/active_record" 
config.picture_model { Ckeditor::Picture } 
    # config.attachment_file_model { Ckeditor::AttachmentFile } 

    Rails.application.config.assets.precompile += %w(ckeditor/filebrowser/images/gal_del.png) 

    config.cdn_url = "//cdn.ckeditor.com/4.5.6/standard/ckeditor.js" 

    config.js_config_url = "/assets/ckeditor/config.js" 
end 

編輯

,這裏是我的CKEditor JS 的CKEditor/config.js

CKEDITOR.editorConfig = function(config) 
{ 
    config.enterMode = 2 
    config.filebrowserBrowseUrl = "/ckeditor/attachment_files"; 
    config.filebrowserFlashBrowseUrl = "/ckeditor/attachment_files"; 
    config.filebrowserFlashUploadUrl = "/ckeditor/attachment_files"; 
    config.filebrowserImageBrowseLinkUrl = "/ckeditor/pictures"; 
    config.filebrowserImageBrowseUrl = "/ckeditor/pictures"; 
    config.filebrowserImageUploadUrl = "/ckeditor/pictures"; 
    config.filebrowserUploadUrl = "/ckeditor/attachment_files"; 
    config.toolbar_Pure = [ 
    '/', { 
     name: 'basicstyles', 
     items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'] 
    }, { 
     name: 'paragraph', 
     items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl'] 
    }, { 
     name: 'links', 
     items: ['Link', 'Unlink'] 
    }, '/', { 
     name: 'styles', 
     items: ['Styles', 'Format', 'Font', 'FontSize'] 
    }, { 
     name: 'colors', 
     items: ['TextColor', 'BGColor'] 
    }, { 
     name: 'insert', 
     items: ['Image', 'Table', 'HorizontalRule', 'PageBreak'] 
    } 
    ]; 

    config.allowedContent = true; 
    config.toolbar = 'Pure'; 
    return true; 
} 

回答

0
[: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 Carrierwave Cloudinary

相關問題