0
votes

I am using gem devise. And I overrided devise registrations controller and everything went great, but the problem is redirect path after it is saved. What I want to do is after user saved, it redirects to profile_path, but what I have now is user need to sign in before it redirect to profile path. How can I solve that? Here is my register controller:

class RegistrationsController < Devise::RegistrationsController
  def new
    super
  end

  def create
      @user= User.new(params[:user])
      if @user.save
    redirect_to profile_path, notice: 'User was successfully created.'
  else
    render action: "new"
  end

  end

  def update
    super
  end
end

And this is my application controller which control the path after sign up and sign in:

class ApplicationController < ActionController::Base
    protect_from_forgery

    def after_sign_in_path_for(resource)
        if request.path !~ /^\/admins\//i 
            resource.sign_in_count <= 1  ? '/profile' : root_path
        end
    end
end

Before I override the register controller, redirect after sign up went great. Would be really glad if anyone could help. Thanks.

1

1 Answers

0
votes

You have to sign the user in in your create method:

if @user.save
  sign_in(resource_name, resource)
  current_user = @user # !! now logged in
  redirect_to profile_path, notice: 'User was successfully created.'
else

You can look at the original create method in Devise::RegistrationsController to see how this works.