你如何使用常规路线而不是引擎路线
How do you use regular routes over engine routes
我有一个安装引擎的 rails 应用程序,使用引擎路由 ID 做 engine_name.route_name_from_said_engine_path
并使用我会做的常规应用程序路由 route_name_path
。虽然这适用于未经测试的代码,但第二次我 运行 我的测试,测试失败,因为应用程序路由 "not existing".
我的申请路径文件:
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'
...
每个测试都因此而失败,但我可以启动应用程序并访问这条路线,它工作得很好。
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>
我的测试失败是因为:
<li><%= link_to 'Application Api Key Management', application_api_keys_path %></li>
在引擎路由上使用应用程序路由时,我应该做一些特别的事情吗?
在我看来不像,但如果布局文件在引擎中,则需要使用 main_app.route_path
。还有一点要注意:
"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:"
module Blorgh
class FooControllerTest < ActionController::TestCase
setup do
@routes = Engine.routes
end
def test_index
get :index
...
end
end
end
来源:http://guides.rubyonrails.org/engines.html#testing-an-engine。不确定这是否是您的问题,但可以随时尝试。
我有一个安装引擎的 rails 应用程序,使用引擎路由 ID 做 engine_name.route_name_from_said_engine_path
并使用我会做的常规应用程序路由 route_name_path
。虽然这适用于未经测试的代码,但第二次我 运行 我的测试,测试失败,因为应用程序路由 "not existing".
我的申请路径文件:
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'
...
每个测试都因此而失败,但我可以启动应用程序并访问这条路线,它工作得很好。
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>
我的测试失败是因为:
<li><%= link_to 'Application Api Key Management', application_api_keys_path %></li>
在引擎路由上使用应用程序路由时,我应该做一些特别的事情吗?
在我看来不像,但如果布局文件在引擎中,则需要使用 main_app.route_path
。还有一点要注意:
"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:"
module Blorgh
class FooControllerTest < ActionController::TestCase
setup do
@routes = Engine.routes
end
def test_index
get :index
...
end
end
end
来源:http://guides.rubyonrails.org/engines.html#testing-an-engine。不确定这是否是您的问题,但可以随时尝试。