简体   繁体   English

您如何在引擎路线上使用常规路线

[英]How do you use regular routes over engine routes

I have a rails application that mounts an engine, to use the engine route Id do engine_name.route_name_from_said_engine_path And to use the regular applications routes I would do route_name_path . 我有一个安装引擎的Rails应用程序,使用引擎路由ID执行engine_name.route_name_from_said_engine_path并使用常规应用程序路由,我会执行route_name_path While this works for non tested code, the second I run my tests, the tests fail, because of the application route "not existing". 虽然这适用于未经测试的代码,但第二次我运行测试时,由于应用程序路由“不存在”,测试失败。

My routes File for the application: 我的路线该应用程序的文件:

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

One of my tests, a capybara test, is failing because: 我的一项测试(水豚测试)失败了,因为:

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'
     ...

Every test is failing because of this, Yet I can boot up the application and go and visit this route and it works perfectly fine. 因此,每个测试都失败了,但是我可以启动应用程序,然后访问此路由,它运行得很好。

This particular route on the xaaron/application.html.erb looks like: xaaron/application.html.erb上的特定路由如下所示:

        <ul class="dropdown-menu">
          <li><%= link_to 'Users', xaaron.users_path %></li>
          <li><%= link_to 'Group Management', xaaron.groups_path %></li>
          <li><%= link_to 'Role Management', xaaron.roles_path %></li>
          <li><%= link_to 'Permission Management', xaaron.permissions_path %></li>
          <li class="divider"></li>
          <li><%= link_to 'Application Api Key Management', application_api_keys_path %></li>
        </ul>

My tests are failing because of: 我的测试因以下原因而失败:

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

Is there something special I am suppose to do when using application routes over engine routes? 在引擎路由上使用应用程序路由时,我想做些特别的事情吗?

Doesnt look like it to me, but if the layout file is in the engine, you need to use main_app.route_path . 在我看来,它看起来并不像,但是如果布局文件在引擎中,则需要使用main_app.route_path One other thing to note: 需要注意的另一件事:

"The application doesn't know how to route these requests to the engine unless you explicitly tell it how. To do this, you must set the @routes instance variable to the engine's route set in your setup code:" “除非您明确告诉它如何,否则应用程序不知道如何将这些请求路由到引擎。为此,必须将@routes实例变量设置为在设置代码中设置的引擎的路由:”

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

    def test_index
      get :index
      ...
    end
  end
end

Sourced from: http://guides.rubyonrails.org/engines.html#testing-an-engine . 来源: http : //guides.rubyonrails.org/engines.html#testing-an-engine Not sure if that's your issue here, but could always try it. 不知道这是否是您的问题,但可以随时尝试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM