2

Use Case:

  1. Admin should be able to create user, and it should not attempt to login.
  2. Public User can crate account and after signup he should be redirected to sign-in page rather signing him in immediately.

Can somebody help me with this ?

Thanks :)

Syed
  • 15,657
  • 13
  • 120
  • 154

1 Answers1

6

What you need to do is to override Devise's RegistrationsController create method.

There is an excellent explanation for how to do it here.

This is Devise create action:

  # POST /resource
  def create
    build_resource

    if resource.save
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_navigational_format?
        sign_in(resource_name, resource)
        respond_with resource, :location => after_sign_up_path_for(resource)
      else
        set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
        expire_session_data_after_sign_in!
        respond_with resource, :location => after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      respond_with resource
    end
  end

After you override the controller, just remove sign_in(resource_name, resource)

You can also set the method after_sign_up_path_for(resource) to fit your needs

Community
  • 1
  • 1
Erez Rabih
  • 15,562
  • 3
  • 47
  • 64
  • Note : with the newer version, the `sign_in(resource_name, resource)` is replace with `sign_up(resource_name, resource)`. It does exactly the same thing, but allows you to override only the sign_up method in your controller. – Sunder Oct 01 '15 at 06:35
  • 1
    replace `expire_session_data_after_sign_in!` with `expire_data_after_sign_in!` – lighter Apr 30 '16 at 15:25