我正在为用户使用 designise,但我有两种类型的用户(客户和供应商),并且需要根据他们遵循的路径进行不同的重定向路由。EG:如果客户登录(/signup
),它会将他们重定向到他们的仪表板。如果供应商注册(/suppliers/registrations/user
),则需要将他们引导到下一个表格,在那里他们开始描述他们的业务(/suppliers/registrations/business
)。你如何管理这个?
更新我已经更新了我的设计注册控制器以包含以下内容(我已经排除了所有注释掉的东西)
users/registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
if resource.supplier == true
redirect_to supplier_business_path
elsif resource.supplier == false
redirect_to user_projects_path(current_user)
end
end
end
但无论如何,它一直把我带到根源。
after_sign_in_path_for应该只返回路径而不执行重定向,请尝试像这样更改方法:
protected
def after_sign_up_path_for(resource)
if resource.supplier == true
# also add specific url = '/suppliers/registrations/user'
supplier_business_path
elsif resource.supplier == false
user_projects_path(current_user)
end
end
另请参阅此链接:https://github.com/plataformatec/devise/wiki/How-To:-重定向到特定页面成功注册-(注册)
在应用程序控制器中使用设计after_sign_in_path_for
方法。例如
def after_sign_in_path_for(resource)
if resource.role == "customer"
redirect_to customer_dashboard_path
elsif resource.role == "supplier"
redirect_to supplier_dashboard_path
end
end