Reputation: 357
I am creating my first rails engine to handle remote authentication in a rails 4 application. I am using http://guides.rubyonrails.org/engines.html as my guide for helping me with this.
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. 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?
Upvotes: 1
Views: 218
Reputation: 10406
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 %>
Upvotes: 1