Hi,
I'm trying to incorporate Devise into a newly created engine that is mounted in the main app as well as ensuring that the main app's Devise functionality continues to function properly.
Here's a bit of background to how my app is configured:
The main app is already using Devise for the 'User' model and users can use this functionality just fine, registering, logging in and out, etc.
There is another model, 'Contact', that I want to control registering, logging in and out, etc. for as well, but from a mountable engine that I have created. The reasons for an engine are as it provides quite different functionality to the main app but they need to share the same data as contact attributes can be accessed from within the main app (by users) as well. I want to use Devise for the 'Contact' model, for the Devise flow from to work from within the new mountable engine I have created.
main_app -> User logs in/out
main_app/contact_engine -> Contact logs in/out
I can get the mountable engine to work with Devise and the Contact model, when I get it to work with the engine though, Devise stops working properly for the main app. It seems the Devise config's clash as there is now a devise.rb initializer in the main app as well as in the engine. Whichever thing is loaded first, based on the railties_order setting in the application.rb config file in the main app, sets up Devise to use for the entire app. So to get the engine to work I set it to be loaded first.
I took a bit out of here too to make it work in the engine:
https://github.com/plataformatec/devise/wiki/How-To:-Use-devise-inside-a-mountable-engineI'll just show a few little snippets of code to show how I'm configuring Devise:
---------
main_app config/application.rb
config.railties_order = [Contact::Engine, :main_app, :all]
---------
main_app config/routes.rb
devise_for :users
mount Contact::Engine, :at => "/contact_engine"
---------
main_app config/devise.rb
config.encryptor = :authlogic_sha512
config.scoped_views = true
config.default_scope = :user
---------
engine config/routes.rb
devise_for :contacts, {
class_name: 'Contact',
module: :devise,
}
--------
engine config/devise.rb
config.scoped_views = true
config.default_scope = :contact
config.router_name = :contact_engine
config.parent_controller = 'Contact::ApplicationController'
--------
So is there a way where I can get both of my Devise'd models/paths to function properly?
Thanks for any help!