设计+主动管理重定向

js1*_*111 5 ruby-on-rails devise ruby-on-rails-3 ruby-on-rails-3.1 activeadmin

我无法为我的应用程序设置重定向.用户应该转到他们的个人资料(用户/节目)和管理员应该去管理仪表板..我如何设置它?

目前收到以下错误:

 NameError in ActiveAdmin::Devise::SessionsController#create

    undefined local variable or method `admin' for #<ActiveAdmin::Devise::SessionsController:0x007febe12667e8>
Run Code Online (Sandbox Code Playgroud)

应用控制器

def after_sign_in_path_for(resource_or_scope)
   if admin
   redirect_to admin_dashboard_path
  else
   @user
  end
 end
end
Run Code Online (Sandbox Code Playgroud)

Dan*_*ans 14

您没有admin要访问的变量,您需要检查您正在给出的参数.

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
Run Code Online (Sandbox Code Playgroud)

你也应该不是这个方法里面重定向,它应该只返回设计可以使用路径.

  • 使用`rails g active_admin:install`的默认设置会创建一个AdminUser类,因此我必须将其修改为`if resource.is_a?(AdminUser)`. (4认同)