Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override DeviseController base class - Rails 4, Devise 3

I am trying to override the Devise method set_flash_message. Devise documentation covers how to override controllers for the various submodules.

However this particular method is located within DeviseController, the parent class of all the modules.

The documentation (both wiki and inline) says nothing about how to achieve this, so I'm not sure how best to proceed. I believe the best approach would be to simply re-open the class and modify the method as needed, and I placed a file in /lib to that effect. However it appears that is getting loaded prior to Devise, resulting in error spew.

NameError in Devise::RegistrationsController#new
undefined local variable or method `require_no_authentication' for #<Devise::RegistrationsController>

The complex parent definition for DeviseController may also be having an net negative effect:

class DeviseController < Devise.parent_controller.constantize

Thoughts?

like image 228
Frank Koehl Avatar asked Feb 14 '14 02:02

Frank Koehl


1 Answers

Devise.parent_controller is defined in the Devise module definition in devise/devise.rb. Luckily, it has mattr_accessor declared, so you can set the value yourself (the default value is "ApplicationController"). It probably makes the most sense to do this some time in your application initialization process, for example, along with the rest of the Devise configuration in initializers/devise.rb.

like image 116
Diana Avatar answered Nov 03 '22 23:11

Diana