Rails父应用程序路由到引擎路由和子项

时间:2015-09-27 21:59:19

标签: ruby-on-rails routes ckeditor

在我的Rails App中,我安装了一个引擎,它有ckeditor的路径。要使ckeditor工作,它需要/ckeditor路径路径。

目前我的应用程序的路由已将引擎安装在/portfolio,以便ckeditor的路由为/portfolio/ckeditor。这不起作用,因为ckeditor正在查找路由/ckeditor和子路由,例如/ckeditor/pictures/...,这很好。

如何让我的应用将/ckeditor映射为/portfolio/ckeditor的别名,或者如何让引擎将ckeditor直接挂载到/ckeditor

以下是我的路线档案:

app route file:

Rails.application.routes.draw do
  root 'front_page#index'
  get 'front_page/index'
  match '/about', to: 'front_page#about', via: 'get'
  match '/contact', to: 'front_page#contact', via: 'get'
  mount BasicProjects::Engine => '/portfolio'

  devise_for :users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)

end

引擎路线文件

BasicProjects::Engine.routes.draw do
  mount Ckeditor::Engine => '/ckeditor'
  resources :projects
  resources :categories
  root 'projects#index'
end

或者,ckeditor初始值设定项是否有办法将ckeditor的路径路径设置为/portfolio/ckeditor而不是/ckeditor

2 个答案:

答案 0 :(得分:0)

您可以配置ckeditor,以便它根据自定义URI构建路径。根据ckeditor的文档,您可以通过设置名为CKEDITOR_BASEPATH的全局javascript变量来实现此目的:

http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Specifying_the_Editor_Path

ckeditor gem在其文档中也有一个示例,说明如何执行此操作:

包括自定义的CKEDITOR_BASEPATH设置

添加你的app / assets / javascripts / ckeditor / basepath.js.erb

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

来源:https://github.com/galetahub/ckeditor#include-customized-ckeditor_basepath-setting

答案 1 :(得分:0)

要覆盖默认的CKEditor路由,请在主机应用程序中创建一个config.js文件。

# in app/assets/javascripts/ckeditor/config.js

CKEDITOR.editorConfig = function( config )
{
  /* Filebrowser routes */
  // The location of an external file browser, that should be launched when "Browse Server" button is pressed.
  config.filebrowserBrowseUrl = "/some_path/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 = "/some_path/ckeditor/attachment_files";

  // The location of a script that handles file uploads in the Flash dialog.
  config.filebrowserFlashUploadUrl = "/some_path/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 = "/some_path/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 = "/some_path/ckeditor/pictures";

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

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