Rails application does not find debugging features when installing with Engine

I am creating a Rails Engine to handle all authentication and authorization across multiple applications. All of these applications use Devise atm to authenticate them. I want to move this to an engine that can then be mounted in all of these applications so that they automatically have all the functionality.

I followed all the steps in the Design Engine guide on the wiki. The problem I'm starting in is that I cannot use functions such as "current_user" and "new_user_session_path" in the controllers of my main applications.

The error I get in the main application:

Showing .../main_app/app/views/shared/_header.haml where line #19 raised: undefined local variable or method `new_user_session_path' for #<#<Class:0x007f1578968040>:0x007f157897b348> = link_to t('user.login'), new_user_session_path 

There is no isolated_space in the engine. I added Devise as a dependency in the engine.gemspec file and removed Devise from the Gemfile in the main application. The engine is mounted in the main application as:

 mount Engine::Engine, at: 'idms' 

In engine routes, I designed a configuration like:

 devise_for :users, { class_name: "IdmsGem::User", module: :devise controllers: { sessions: "devise/sessions" } } 

The initializers file /devise.rb is as follows:

 require 'devise/orm/active_record' Devise.setup do |config| config.router_name = '/idms_gem' end 

User model in the engine:

 module Engine class User < ActiveRecord::Base devise :database_authenticatable self.table_name = "users" end end 

Im using Rails 4.2.1 with Devise 3.5.1 on Ruby 2.2.2.

My question is , how can I allow my controllers and views in my main applications to access functions from the device configured in my engine?

Any help is appreciated! Over the past two days, I have searched many times and searched for everything. Thanks everyone!

EDIT: Route routes give the following result:

 Prefix Verb URI Pattern Controller#Action idms_gem /idms IdmsGem::Engine {AND THE REST OF MY MAIN APP ROUTES...} Routes for IdmsGem::Engine: new_user_session GET /users/sign_in(.:format) devise/sessions#new user_session POST /users/sign_in(.:format) devise/sessions#create destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy root GET / devise/sessions#new 
+5
source share
1 answer

You need to provide a link to the engine. This will try to navigate to the application path.

 link_to t('user.login'), new_user_session_path 

So change it (I think this is correct)

 link_to t('user.login'), IdmsGem.new_user_session_path 
+2
source

All Articles