Ckeditor在根URI中搜索资产,而它的应用程序在子URI上

时间:2013-02-20 21:37:55

标签: ruby-on-rails-3 ckeditor asset-pipeline

我花了两天时间试图修复这个错误,但我真的没有任何想法或工具来解决它。我想知道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/ 网站 /assets/ckeditor/config.js?t=C3HA5RM

我真的在网上搜索试图找到解决方案,但我发现的只有少数类似的情况并没有为我提供解决方案。

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

我也尝试过手动操作CKEDITOR_BASEPATH和Ckeditor.relative_url,但不能再次成功。

有没有人知道如何解决它?我非常感激。

2 个答案:

答案 0 :(得分: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;
};

答案 1 :(得分:0)

我遇到了ckeditor在 root dir 上搜索皮肤的问题,因为我在整个页面加载后以负面方式加载ckeditor.js。

我在this thread找到的解决方案 是在调用ckeditor.js之前设置全局变量CKEDITOR_BASEPATH。