2

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?

  • Active Admin - original devise controllers
  • normal user - customized controllers.

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

Thanks, Avi

Avi
  • 391
  • 2
  • 3
  • 20
  • This queston has already been answered [here](http://stackoverflow.com/questions/3546289/override-devise-registrations-controller). Hope it helps. – Peeyush Jan 27 '14 at 09:48

1 Answers1

2

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

Saurabh
  • 1,086
  • 1
  • 15
  • 27
  • Thanks for replying. What I am doing is - Already I have all the setup & running project. I have Active Admin integrated. I need to now customize devise controllers. Currently its user/sign_in. As I will be moving devise controllers to app/controllers, should I need to create a new folder as app/controller/user/sessions_controllers.rb ? – Avi Jan 27 '14 at 11:27
  • If you are creating your customised controller and if you want to have namespace in it then the controller should be placed in the namespace folder. You could use the following code rails generate controller admin/Users – Saurabh Jan 27 '14 at 13:52