Ruby on rails 如何使用常规路线而不是发动机路线

Ruby on rails 如何使用常规路线而不是发动机路线,ruby-on-rails,routing,rails-engines,Ruby On Rails,Routing,Rails Engines,我有一个安装引擎的rails应用程序,使用引擎路由Id do engine\u name.route\u name\u from\u said\u engine\u path,使用常规应用程序路由,我会使用route\u name\u path。虽然这适用于未经测试的代码,但在我运行测试的第二次,测试失败,因为应用程序路由不存在 应用程序的我的路由文件: AisisPlatform::Application.routes.draw do resources :application_api

我有一个安装引擎的rails应用程序,使用引擎路由Id do engine\u name.route\u name\u from\u said\u engine\u path,使用常规应用程序路由,我会使用route\u name\u path。虽然这适用于未经测试的代码,但在我运行测试的第二次,测试失败,因为应用程序路由不存在

应用程序的我的路由文件:

AisisPlatform::Application.routes.draw do

  resources :application_api_keys

  root :to => 'home#home'

  get 'whats_is_aisis_platform' => 'marketing#platform', :as => 'platform'
  get 'using_aisis_platform' => 'marketing#using_platform', :as => 'using_platform'
  get 'data_syncing' => 'marketing#data_syncing', :as => 'data_syncing'
  get 'help_center' => 'help#help_center', :as => 'help_center'

  mount Xaaron::Engine => ""
end
我的一个测试,水豚测试,失败了,因为:

Roles Delete role should delete a role (flash)
     Failure/Error: visit xaaron.roles_path
     ActionView::Template::Error:
       undefined local variable or method `application_api_keys_path' for #<#<Class:0x007f80cb84cb48>:0x007f80c65b86c0>
     # ./app/views/layouts/xaaron/application.html.erb:42:in `_app_views_layouts_xaaron_application_html_erb__814247150210445120_70095544064680'
     ...
我的测试失败是因为:

<li><%= link_to 'Application Api Key Management', application_api_keys_path %></li>

在引擎路由上使用应用程序路由时,我想做些什么特别的事情吗?

在我看来不是这样,但如果布局文件在引擎中,则需要使用main\u app.route\u路径。还有一件事需要注意:

应用程序不知道如何将这些请求路由到引擎,除非您明确告诉它如何路由。为此,必须在设置代码中将@routes实例变量设置为引擎的路由集:

module Blorgh
  class FooControllerTest < ActionController::TestCase
    setup do
      @routes = Engine.routes
    end

    def test_index
      get :index
      ...
    end
  end
end
来源:。不确定这是否是你的问题,但可以尝试一下

module Blorgh
  class FooControllerTest < ActionController::TestCase
    setup do
      @routes = Engine.routes
    end

    def test_index
      get :index
      ...
    end
  end
end