[英]Rails Parent app route to engine route and children
在我的Rails App中,我安裝了一個引擎,該引擎具有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在其文檔中也有一個有關如何執行此操作的示例:
添加您的應用程序/資產/javascript/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";
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.