title: Extend base DeviseController class with method for callbacks in SessionsController and RegistrationsController
body: <p>My question is similar to <a href="https://stackoverflow.com/questions/21769980/override-devisecontroller-base-class-rails-4-devise-3">this one</a>, which doesn't have an answer.</p>
  
  <p>I want to add <code>after_filter :identify_with_segment, only: [:create]</code> to both my <code>RegistrationsController &lt; Devise::RegistrationsController</code> and <code>SessionsController &lt; Devise::SessionsController</code>. Since both of these controllers themselves inherit from <code>DeviseController</code>, I thought that a DRY way to do this would be to extend <code>DeviseController</code> and define the method there. However, I keep getting an <code>unitialized constant</code> error. </p>
  
  <p>My code:</p>
  
  <pre><code>class DeviseController &lt; DeviseController
    def identify_with_segment
      ..
    end
  end
  </code></pre>
  
  <p>I realize the way this class is defined just looks wrong. I've also tried <code>class DeviseController &lt; Devise::DeviseController</code> but that doesn't work either. </p>
  
  <p>Can anyone explain the proper way to extend the <code>DeviseController</code> that these other controllers depend on?</p>