First create an engine, for example with name 'cms'.
$ rails plugin new cms --mountable
This command will create full file tree for your engine.
Use manual and some extra tips from below - https://github.com/plataformatec/devise/wiki/How-To:-Use-devise-inside-a-mountable-engine.
Steps and tips:
-
Install Devise into your engine as usual.
-
In your MasterApp add Devise cofiguration:
2.1) If your engine models, controllers e.t.c. are isolated - covered with 'EngineName' module you need to tell devise about that:
Devise.setup do |config|
# this will tell devise that all models and controllers lies in MyEngine module
config.router_name = :cms
# this will tell to Devise's controllers to inherit from your
# engine's controller and not the main controller.
config.parent_controller = 'Cms::ApplicationController'
end
2.2) If your are on un-safe road, and do not use isolation do not use options from 2.1. Just write your models and controllers without engine namespace. Be carefull, this way means that all controllers from engine will be mixed with your MasterApp controllers. This may cause errors and collisions.
- Add Routes for you devise model in you MasterApp:
# mount Cms routes to root route
mount Cms::Engine => '/'
# add devise routes for User model
# 3.1 if you are using isolated models than tell about this in routes
devise_for :users, { class_name: 'Csm::User',
module: :devise,
# Example of how to override controllers for devise
controllers: { sessions: 'sessions',
registrations: 'registrations',
passwords: 'passwords',
confirmations: 'confirmations' }}
# 3.2 for non isolated User model
devise_for :users, {
# Example of how to override controllers for devise
controllers: { sessions: 'sessions',
registrations: 'registrations',
passwords: 'passwords',
confirmations: 'confirmations' }}
# devise scopes
devise_scope :user do
get '/login', :to => 'main#index'
end
Tips:
-
if you have an error like:
Undefined method Cms ...
and using isolation check you models, they should be covered with Cms module