Search code examples
ruby-on-railsauthenticationdeviseruby-on-rails-6

Rails Authentification with Devise: Redirect to Sign-In form after Sign-Up


I'm building an authentication using Devise.

Creating users works, but after the creation the user is automatically logged-in and becomes redirected to the root-page.

I have created an own RegistrationController and overwritten the after_sign_up_path method:

class RegistrationsController < Devise::RegistrationsController
    def after_sign_up_path_for(resource)
        "/users/sign_in"
    end
end

But it doesn't work.

What have I done wrong, respectively what have I missed.

I have read various other StackOverflow question already. Until now nothing has worked.

Here's my routes.rb too:

Rails.application.routes.draw do
  resources :comments
  resources :posts
  devise_for :users, controllers: { registrations: "registrations" }
  root "posts#index"
end

Solution

  • This is the default sign up method that ships with the RegistrationsController

      # Signs in a user on sign up. You can overwrite this method in your own
      # RegistrationsController.
      def sign_up(resource_name, resource)
        sign_in(resource_name, resource)
      end
    

    You can override it in your code.