首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >RAILS 5:上传图片后,浏览服务器路径错误'undefined method‘CKEditor’‘

RAILS 5:上传图片后,浏览服务器路径错误'undefined method‘CKEditor’‘
EN

Stack Overflow用户
提问于 2016-09-06 01:34:00
回答 1查看 757关注 0票数 -1

我只是在ckeditor中上传图片,包括carrierwave和cloudinary,我已经尝试过一次,它工作得很好,我可以在我的笔记本电脑上浏览图片,并通过ckeditor中的图片上传器上传到cloudinary。但当我尝试编辑或创建新文章,并尝试上传图片时,图片上传程序不再起作用。我不知道为什么,我没有编辑任何东西后,成功地使图像上传。有人能帮我吗?不管怎样,thx

错误如下所示

这是我的model/ckeditor/asset.rb

代码语言:javascript
复制
class Ckeditor::Asset < ActiveRecord::Base

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

model/ckeditor/picture.rb

代码语言:javascript
复制
class Ckeditor::Picture < Ckeditor::Asset
  mount_uploader :data, CkeditorPictureUploader, mount_on: :data_file_name

  def url_content
    url(:content)
  end
end

model/ckeditor/attachment_file.rb

代码语言:javascript
复制
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

uploader/ckeditor/ckeditor_picture_uploader.rb

代码语言:javascript
复制
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

config/initializers/ckeditor.rb

代码语言:javascript
复制
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

代码语言:javascript
复制
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;
}
EN

回答 1

Stack Overflow用户

发布于 2017-08-24 05:23:33

代码语言:javascript
复制
  [: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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39335359

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档