我已经开始使用Devise进行自定义系统的Rails项目。 但在我的场景中,还有一个管理部分。 因此,管理员和普通用户都使用由Devise创建的“用户”模型。 我将“is_admin”字段添加到带有迁移的Model中。 但这次我有两个主要问题。
首先,我需要在admin部分有一个登录页面,它将使用Devise的登录方法,如果用户自动验证并查找“is_admin”字段以将用户重定向到管理页面。
第二个是,应该有常规站点的另一个登录页面,人们会看到。 这不会查找“is_admin”字段,而是使用常规的Devise登录表单。
那么这些可能与Devise有关吗?
谢谢
I have started a Rails project with Devise for authantication system. But in my scenerio, there is also an admin section. So both admin and regular users use the "User" model, which was created by Devise. I added "is_admin" field to Model with migrations. But this time i have 2 main problems.
First one is, i need to have a login page in admin section, which will use the Devise's login methods and if the user authanticate and look for the "is_admin" field to redirect user to admin pages.
Second one is, there should be another login page for the regular site, which people will see. This will not look for the "is_admin" field and will use regular Devise login forms.
So are these possible with Devise?
Thanks
最满意答案
在应用程序控制器中放置一个after_sign_in函数,如下所示,它将检查用户角色,然后重定向
class ApplicationController < ActionController::Base def after_sign_in_path_for(resource) if resource.is_admin? redirect_to admin_path else redirect_to user_path end end endIn the application controller place an after_sign_in function as below that would check for the user role and then redirect
class ApplicationController < ActionController::Base def after_sign_in_path_for(resource) if resource.is_admin? redirect_to admin_path else redirect_to user_path end end end更多推荐
Devise,is_admin,admin,login,使用,电脑培训,计算机培训,IT培训"/> <meta name=&quo
发布评论