Devise + Active Admin Redirect

I'm having trouble setting up redirection for my application. Users should go to their profile (users / show), and administrators should go to the admin control panel. How do I configure this?

The following error is currently appearing:

 NameError in ActiveAdmin::Devise::SessionsController#create

    undefined local variable or method `admin' for #<ActiveAdmin::Devise::SessionsController:0x007febe12667e8>

Application controller

def after_sign_in_path_for(resource_or_scope)
   if admin
   redirect_to admin_dashboard_path
  else
   @user
  end
 end
end
+5
source share
2 answers

You do not have a variable adminfor access, you need to check which parameter is specified for you.

def after_sign_in_path_for(resource)
  stored_location_for(resource) ||
    if resource.is_a?(Admin)
      admin_dashboard_path
    else
      user_path(resource)
    end
end

You also should not redirect inside this method, it should only return a path that the development method can use.

+14
source
if resource.class == User
  root_path
elsif resource.class == AdminUser
  admin_root_path
else
end
0
source

All Articles