title: redirect when signout devise rails
body: <p><em>Rails 4.2 and Devise 5</em></p>
  
  <p>i'm using this <a href="https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in,-sign-out,-sign-up,-update" rel="nofollow noreferrer">code</a> on my application_controller.rb to redirect user to the same page when they sign out </p>
  
  <pre><code>def after_sign_out_path_for(resource_or_scope)
     request.referrer || root_path
  end
  </code></pre>
  
  <p>everything works fine, when user click sign out they will sign out and stay on the same page. </p>
  
  <p>However if user try to sign out on failed validation edit profile*  the application throws  error. the log says "ActionController::RoutingError (No route matches [GET] "/users").</p>
  
  <p>Any idea to improve the code?</p>
  
  <p>*(for example, when user tries to change username and it's already taken, the form give validation error and the user sign out ) </p>