【问题标题】:customized CKEDITOR_BASEPATH setting自定义 CKEDITOR BASEPATH 设置
【发布时间】:2015-08-05 05:59:29
【问题描述】:

我想要一个自定义的 CKEDITOR_BASEPATH 引用 https://github.com/galetahub/ckeditor

我的应用程序在 baseURL 上运行,如下所示 http://localhost:3000/tutorsaround

因此,我将“app/assets/javascripts/ckeditor/basepath.js.erb”更改为

<%
  base_path = '/tutorsaround'
  if ENV['PROJECT'] =~ /editor/i
    base_path << "/#{Rails.root.basename.to_s}/"
  end
  base_path << Rails.application.config.assets.prefix
  base_path << '/ckeditor/'
  puts "#{base_path}"
%>
var CKEDITOR_BASEPATH = '<%= base_path %>';

但是,当我转到其他页面时,我在控制台中看到了错误。 GET http://localhost:3000/tutorsaround/boards/tutorsaround/assets/ckeditor/config.js?t=F0RD 404(未找到)

似乎在每个子路径之后插入了路径,而不是http://localhost:3000/

所以我的问题是如何为 CKeditor 添加一个 base_path,它的基本 url 始终是 http://localhost:3000/tutorsaround 并且每当它想要引用 js 源时,它将是 http://localhost:3000/tutorsaround/assets/ckeditor/......

EDIT2 我将 base_path 放在终端中,它输出“tutorsaround/assets/ckeditor/” 我的问题是这个字符串在“localhost:3000/”之后没有连接。但是,任何使用 CKEditor 的页面都会在页面 url 上连接此字符串。例如,如果“localhost:3000/boards”有CK编辑器,那么它会尝试通过“http://localhost:3000/boards/tutorsaround/assets/ckeditor/config.js?t=F0RD”获取资源 如果“localhost:3000/boards/1”已经使用了CKEditor,那么它会尝试从“http://localhost:3000/boards/1/tutorsaround/assets/ckeditor/config.js?t=F0RD”获取

【问题讨论】:

标签: ruby-on-rails ckeditor ckeditor4.x


【解决方案1】:

编辑: 请再次检查下面的代码示例,因为最初我发布它们时没有您的自定义路径前缀

尝试删除条件(将行保留在其中):

<%
  base_path = '/tutorsaround'
  base_path << "/#{Rails.root.basename.to_s}/"
  base_path << Rails.application.config.assets.prefix
  base_path << '/ckeditor/'
 %>

或者如果这不起作用尝试:

<%
  base_path = '/tutorsaround'
  base_path << Rails.application.config.assets.prefix
  base_path << '/ckeditor/'
%>

编辑2

app/assets/javascripts/application.js在init之前添加basepath依赖:

//= require ckeditor/basepath
//= require ckeditor/init

【讨论】:

  • 其实我都试过了。唯一的问题是我的索引页不在 localhost 中,而是在 localhost/tutorsaround 中,所以我需要一个 base_path。但是,一旦我有了 base_path,行为就很奇怪,因为每当我转到子页面时,例如“localhost/tutorsaround/board/”,ckeditor 的相应路径就变成了“localhost/tutorsaround/board/tutorsaround/ckeditor.. ..'
  • 我在生产中制作了该网站,因此您可能会看到错误。我在原来的帖子中有更新
  • 在您的示例代码中,您在 toursaround 之前缺少“/” - 在您定义基本路径的第一行。
  • 我变了。但是,这似乎不是关键问题
  • 您能否分享您的应用程序布局页面或您将 ckeditor 作为资产包含的任何位置?
猜你喜欢
  • 1970-01-01
  • 2016-01-15
  • 1970-01-01
  • 1970-01-01
  • 2015-07-24
  • 2014-02-15
  • 2017-03-29
  • 2023-01-18
  • 2012-07-14
相关资源
最近更新 更多