Rails 4 ckeditor file upload

2019-05-10 23:46发布

I'm using ckeditor in my rails projec and I have a problem with image uploading. I don't want everything that ckeditor have, that I wrote some simple config.js for it:

CKEDITOR.editorConfig = (config) ->
  config.language = 'pl'
  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.toolbar = 'Pure'
  true

and in my view:

= f.input :answer, label: false, :as => :ckeditor, :input_html => { :ckeditor => {:toolbar => 'Pure'} } 

And with this config I don't have a button to select image from my computer: enter image description here

But when I delete my config.js and in view set:

= f.input :answer, label: false, :as => :ckeditor, :input_html => { :ckeditor => {:toolbar => 'Full'} }

then I have the button to upload file from my computer and everything works fine. Now my goal is to edit my config.js to have this file upload working. Please help.

1条回答
你好瞎i
2楼-- · 2019-05-11 00:19

I change my config to:

CKEDITOR.editorConfig = function(config) {
  config.language = 'pl';
  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.toolbar = 'Pure';
  return true;
};

and works as expected

查看更多
登录 后发表回答