Avi
Avi

Reputation: 391

Customizing devise controllers

I want to customize devise session & registration controller. I am even adding Active Admin to the app.

What is the correct process to override these controllers?

& I want to use both the controllers(customized as well as original). Is it possible?

When we are creating customized controllers, does same name cause any problem?

Thanks, Avi

Upvotes: 2

Views: 2430

Answers (1)

Saurabh
Saurabh

Reputation: 1104

If you want to add a admin role to your devise, have a look at https://github.com/plataformatec/devise/wiki/How-To:-Add-an-Admin-role. If you want to customise your current devise You can customise the devise views by copying the views from the gem into your application and then modifying them. The below line would copy the views into your application

rails generate devise:views

If you want to modify controllers, Follow below steps

  1. You would have to create your own customise controller say Admins::SessionsController

    class Admins::SessionsController < Devise::SessionsController
    end
    

Note that in the above example, the controller needs to be created in the app/controller/admins/ directory.

  1. Now tell the router to use this controller

     devise_for :admins, :controllers => { :sessions => "admins/sessions" }
    
  2. And since we changed the controller, it won't use the "devise/sessions" views, so remember to copy "devise/sessions" to "admins/sessions".

There is a rail cast video for active admin at http://railscasts.com/episodes/284-active-admin

Upvotes: 2

Related Questions