简体   繁体   中英

Devise + Active Admin Redirect

I am having trouble setting up the redirect for my application. Users should go to their profile (users/show) and admins should go to the admin dashboard.. How do i set this up?

Currently getting the following error:

 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

You don't have an admin variable to access, you need to check what the parameter is that you are being given.

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 should also not redirect inside this method, it should only return a path that devise can use.

if resource.class == User
  root_path
elsif resource.class == AdminUser
  admin_root_path
else
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM