Rails 父应用程序路由到引擎路由和子应用程序
Rails Parent app route to engine route and children
在我的 Rails 应用程序中,我安装了一个引擎,它有一条通往 ckeditor 的路线。为了让 ckeditor 工作,它需要 /ckeditor
路由路径。
目前我的应用程序的路由在 /portfolio
上安装了引擎,因此到 ckeditor
的路由是 /portfolio/ckeditor
。这不起作用,因为 ckeditor 正在寻找路由 /ckeditor
和子路由,例如 /ckeditor/pictures/...
,这很好。
如何让我的应用程序将 /ckeditor
作为别名映射到 /portfolio/ckeditor
或者如何让引擎将 ckeditor 直接挂载到 /ckeditor
?
这是我的路线文件:
应用程序路径文件:
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
?
您可以配置 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
要覆盖默认的 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";
};
在我的 Rails 应用程序中,我安装了一个引擎,它有一条通往 ckeditor 的路线。为了让 ckeditor 工作,它需要 /ckeditor
路由路径。
目前我的应用程序的路由在 /portfolio
上安装了引擎,因此到 ckeditor
的路由是 /portfolio/ckeditor
。这不起作用,因为 ckeditor 正在寻找路由 /ckeditor
和子路由,例如 /ckeditor/pictures/...
,这很好。
如何让我的应用程序将 /ckeditor
作为别名映射到 /portfolio/ckeditor
或者如何让引擎将 ckeditor 直接挂载到 /ckeditor
?
这是我的路线文件:
应用程序路径文件:
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
?
您可以配置 ckeditor,使其基于自定义 URI 构建路径。根据 ckeditor 的文档,您可以通过设置名为 CKEDITOR_BASEPATH
:
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
要覆盖默认的 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";
};