简体   繁体   English

如何获得主Rails应用程序以使用引擎路线

[英]How do I get a main rails application to use an engines route

I am creating my first rails engine to handle remote authentication in a rails 4 application. 我正在创建我的第一个Rails引擎来处理Rails 4应用程序中的远程身份验证。 I am using http://guides.rubyonrails.org/engines.html as my guide for helping me with this. 我使用http://guides.rubyonrails.org/engines.html作为指导来帮助我。

I have created a sessions controller inside the engine which I will be used to handle the authentication logic but I am having a hard time getting my main application to route to the engine to prompt for authentication. 我已经在引擎内部创建了一个会话控制器,该控制器将用于处理身份验证逻辑,但是我很难将主应用程序路由到引擎以提示进行身份验证。

My engines routes file has: 我的引擎路线文件具有:

resources :sessions only: [:new, :create, :destroy]

If I run rake routes, I can see that my routes are there. 如果我运行耙子路线,我可以看到我的路线在那里。 But I am not sure how to access them. 但是我不确定如何访问它们。 for instance: 例如:

auth_test$ rake routes
Prefix Verb URI Pattern            Controller#Action
tests_index GET  /tests/index(.:format) tests#index
my_engine      /my_engine        MyEngine::Engine
root GET  /                      tests#index

Routes for MyEngine::Engine:
sessions POST   /sessions(.:format)     my_engine/sessions#create
new_session GET    /sessions/new(.:format) my_engine/sessions#new
session DELETE /sessions/:id(.:format) my_engine/sessions#destroy

I tried using things in the normal ways such as new_session_path but that doesn't appear to work. 我尝试以常规方式使用事物,例如new_session_path,但这似乎不起作用。 I get the following error: 我收到以下错误:

undefined local variable or method `new_session_path' for #<TestsController:0x007fba02150c20>

How would I specify this route so that my main application knows to use the routes from my engine and not its main routes? 如何指定此路由,以便我的主应用程序知道使用引擎中的路由,而不是其主要路由?

From the app to the engine: 从应用程序到引擎:

<%= link_to "Sessions", my_engine.new_session_path %>

From the engine to the app 从引擎到应用

<%= link_to "Test Index", main_app.tests_index_path %>

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

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