【问题标题】:Rails Parent app route to engine route and childrenRails 父应用程序路由到引擎路由和子级
【发布时间】:2015-09-27 21:59:19
【问题描述】:

在我的 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

【问题讨论】:

    标签: ruby-on-rails routes ckeditor


    【解决方案1】:

    要覆盖默认的 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";
    };
    

    【讨论】:

      【解决方案2】:

      您可以配置 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

      【讨论】:

      • 我将/portfolio 添加到了基本路径中,结果为base_path = '/portfolio',尽管这不会改变路由的工作方式。我错过了什么?
      猜你喜欢
      • 1970-01-01
      • 2011-09-12
      • 1970-01-01
      • 2014-08-03
      • 1970-01-01
      • 2016-07-06
      • 1970-01-01
      • 2016-04-29
      • 2015-09-27
      相关资源
      最近更新 更多