2

过去两天我一直在尝试修复这个错误,但我真的没有更多的想法或工具来解决它。我想知道stackoverflow中是否有人可以帮助我。

我正在尝试修复使用 ckeditor gem 的网站源代码。ckeditor gem 提供了一个嵌入式 Web 文本编辑器。问题是当网站被放置在子目录中时,gem 并不能发挥作用。如果将网站放在像 www.domain.com 这样的根目录中,它可以完美运行,但是当我将它放在子目录中时,例如 www.domain.com/website,它不会显示文本编辑器。

没有显示编辑器的原因是应用程序试图在服务器的根目录中找到 ckeditor gem 的资产:

Failed to load resource: the server responded with a status of 404 (Not Found)             http://domain.com/assets/ckeditor/config.js?t=C3HA5RM
Failed to load resource: the server responded with a status of 404 (Not Found)             http://domain.com/assets/ckeditor/skins/kama/editor.css?t=C3HA5RM
Failed to load resource: the server responded with a status of 404 (Not Found)             http://domain.com/assets/ckeditor/lang/pt-br.js?t=C3HA5RM
Failed to load resource: the server responded with a status of 404 (Not Found)             http://domain.com/assets/ckeditor/plugins/embed/plugin.js?t=C3HA5RM
Failed to load resource: the server responded with a status of 404 (Not Found)             http://domain.com/assets/ckeditor/plugins/attachment/plugin.js?t=C3HA5RM

当正确的地址是 www.domain.com/ website /assets/ckeditor/config.js?t=C3HA5RM

我真的在整个网络上搜索过,试图找到解决方案,但我发现的仅有的几个类似情况并没有为我提供解决方案。

在这个问题中,在 github,用户 jronallo 与我有完全相同的问题。但我试图实施他的解决方案但没有成功。在此提交中,在 ckeditor 存储库中,该错误似乎已修复,但即使在我的 gem(ckeditor 4.0.2 和 rails 3.2.2)上进行了此修复,它仍然缺少 SubUri 上的资产。

我也尝试过手动操作 CKEDITOR_BASEPATH 和 Ckeditor.relative_url,但又没有成功。

有谁知道如何解决它?我会非常感激。

4

2 回答 2

2

在您的 ckeditor 配置外部插件中删除。

加载资源失败:服务器响应状态为 404(未找到) http://domain.com/assets/ckeditor/plugins/embed/plugin.js?t=C3HA5RM 加载资源失败:服务器响应404 状态(未找到) http://domain.com/assets/ckeditor/plugins/attachment/plugin.js?t=C3HA5RM 它的作品!

我的配置:

/*
Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/

CKEDITOR.editorConfig = function( config )
{
    // Define changes to default configuration here. For example:
    config.language = I18n.locale;
    // config.uiColor = '#AADC6E';

  /* Filebrowser routes */
  // The location of an external file browser, that should be launched when "Browse Server" button is pressed.
  config.filebrowserBrowseUrl = "/ckeditor/attachment_files";

  // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Flash dialog.
  config.filebrowserFlashBrowseUrl = "/ckeditor/attachment_files";

  // The location of a script that handles file uploads in the Flash dialog.
  config.filebrowserFlashUploadUrl = "/ckeditor/attachment_files";

  // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Link tab of Image dialog.
  config.filebrowserImageBrowseLinkUrl = "/ckeditor/pictures";

  // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Image dialog.
  config.filebrowserImageBrowseUrl = "/ckeditor/pictures";

  // The location of a script that handles file uploads in the Image dialog.
  config.filebrowserImageUploadUrl = "/ckeditor/pictures";

  // The location of a script that handles file uploads.
  config.filebrowserUploadUrl = "/ckeditor/attachment_files";

  // Rails CSRF token
  config.filebrowserParams = function(){
    var csrf_token = jQuery('meta[name=csrf-token]').attr('content'),
        csrf_param = jQuery('meta[name=csrf-param]').attr('content'),
        params = new Object();

    if (csrf_param !== undefined && csrf_token !== undefined) {
      params[csrf_param] = csrf_token;
    }

    return params;
  };

  config.addQueryString = function (url, params) {
    var queryString = [];

    if (!params)
      return url;
    else {
      for (var i in params)
        queryString.push(i + "=" + encodeURIComponent(params[ i ]));
    }

    return url + ( ( url.indexOf("?") != -1 ) ? "&" : "?" ) + queryString.join("&");
  };

  // Integrate Rails CSRF token into file upload dialogs (link, image, attachment and flash)
  CKEDITOR.on('dialogDefinition', function (ev) {
    // Take the dialog name and its definition from the event data.
    var dialogName = ev.data.name;
    var dialogDefinition = ev.data.definition;
    var content, upload;

    if ($.inArray(dialogName, ['link', 'image', 'attachment', 'flash']) > -1) {
      content = (dialogDefinition.getContents('Upload') || dialogDefinition.getContents('upload'));
      upload = (content == null ? null : content.get('upload'));

      if (upload && upload.filebrowser['params'] == null) {
        upload.filebrowser['params'] = config.filebrowserParams();
        upload.action = config.addQueryString(upload.action, upload.filebrowser['params']);
      }
    }
  });

  /* Extra plugins */
  // works only with en, ru, uk locales
//  config.extraPlugins = "embed,attachment";

    //for orfografii
  config.disableNativeSpellChecker = false;
//  config.removePlugins = 'contextmenu';


  /* Toolbars */
  config.toolbar = 'Mini';
  config.toolbar_Mini =
    [
        ['Source','-','Preview'],
        ['Cut','Copy','Paste','PasteText','PasteFromWord'],
        ['Undo','Redo','-','SelectAll','RemoveFormat'],
//        ['Styles','Format'],
      ['Subscript', 'Superscript'],
//      ['Subscript', 'Superscript', 'TextColor'],
//        ['Maximize','-','About'],
        ['Bold','Italic','Underline'], ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote']//,
//        ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
//        ['Link','Unlink','Anchor'], ['Image', 'Attachment', 'Flash', 'Embed'],
//        ['Table','HorizontalRule','Smiley','SpecialChar','PageBreak']
    ];

  config.toolbar = 'VeryEasy';
  config.toolbar_VeryEasy =
    [
        ['Source','-','Preview'],
        ['Cut','Copy','Paste','PasteText','PasteFromWord'],
        ['Undo','Redo','-','SelectAll','RemoveFormat'],
//        ['Styles','Format'],
      ['Subscript', 'Superscript', 'TextColor'],
        ['Maximize','-','About'],
        ['Bold','Italic','Underline','Strike'], ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
//        ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
//        ['Link','Unlink','Anchor'], ['Image', 'Attachment', 'Flash', 'Embed'],
        ['Table','HorizontalRule','Smiley','SpecialChar','PageBreak']
    ];

  config.toolbar = 'Easy';
  config.toolbar_Easy =
      [
        ['Source', '-', 'Preview'],
        ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord'],
        ['Undo', 'Redo', '-', 'SelectAll', 'RemoveFormat'],
        ['Styles', 'Format'],
        ['Subscript', 'Superscript', 'TextColor'],
        ['Maximize', '-', 'About'],
        '/',
        ['Bold', 'Italic', 'Underline', 'Strike'],
        ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'],
        ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
        ['Link', 'Unlink', 'Anchor'],
        ['Image', 'Attachment', 'Flash', 'Embed'],
        ['Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak']
      ];
  config.jqueryOverrideVal = true;
};
于 2013-02-27T09:48:23.473 回答
0

我在 ckeditor 在根目录上搜索皮肤时遇到问题,因为我在整个页面加载后动态加载 ckeditor.js。

我在这个线程 中找到的解决方案是在调用 ckeditor.js 之前设置全局变量 CKEDITOR_BASEPATH。

于 2013-10-31T23:05:49.353 回答