Kyl*_*cey 9 authentication model devise ruby-on-rails-3 activeadmin
我在项目的早期设置了ActiveAdmin,并使用默认admin_users
模型进行身份验证.我已经使用Devise来设置一个单独的用户模型,并且已经意识到合并这两个表可能会更加智能,这样管理员就可以在Activeadmin和站点的前端进行管理操作.如何配置ActiveAdmin以使用Users模型,可能使用列来标记管理员(例如,is_admin
或者事件是管理员和管理员的权限级别)?
Rails 3.1
ActiveAdmin 0.3.3
Devise 1.4.9
Run Code Online (Sandbox Code Playgroud)
有关如何使用带有activeadmin的现有"用户"模型执行此操作的快速代码块,答案实际上非常简单.在ApplicationController中:
class ApplicationController < ActionController::Base
def authenticate_admin_user! #use predefined method name
redirect_to '/' and return if user_signed_in? && !current_user.is_admin?
authenticate_user!
end
def current_admin_user #use predefined method name
return nil if user_signed_in? && !current_user.is_admin?
current_user
end
end
Run Code Online (Sandbox Code Playgroud)
只需使用Devise已经设置的身份验证.该redirect_to
是你想送谁在签署并没有管理权限的用户.
归档时间: |
|
查看次数: |
3775 次 |
最近记录: |