合并ActiveAdmin用户与现有的用户模型 [英] Merging ActiveAdmin users with existing user model

查看:730
本文介绍了合并ActiveAdmin用户与现有的用户模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成立了ActiveAdmin在我的项目早期使用的默认 admin_users 模型进行验证。因为我已经用设计来建立一个单独的用户模型,并已经意识到这很可能是更聪明合并两个表,这样管理员可以同时在Activeadmin,并在该网站的前端行政行为。如何配置ActiveAdmin使用用户模型也许一列标志管理员(如 is_admin 或事件的权限级别,使管理员和版主)?

  3.1的Rails
ActiveAdmin 0.3.3
1.4.9设计


解决方案

有关如何使用activeadmin做到这一点使用现有的用户模式的快速code座,答案其实是很容易的。在ApplicationController中:

 类的ApplicationController< ActionController的基地::
    高清authenticate_admin_user! #使用predefined方法名
      redirect_to的'/',并且返回是否user_signed_in? &功放;&安培; !current_user.is_admin?
      的authenticate_user!
    结束
    高清current_admin_user#使用predefined方法名
      返回nil如果user_signed_in? &功放;&安培; !current_user.is_admin?
      当前用户
    结束
结束

和只使用什么设计已经设立了认证。在 redirect_to的是要发送谁是签署,并没有管理权限的用户。

I've set up ActiveAdmin early in my project and used the default admin_users model for authentication. I've since used Devise to set up a separate User model and have realized it would probably be much smarter to merge the two tables, such that an Administrator can have administrative actions both in Activeadmin and in the front end of the site. How can I configure ActiveAdmin to use the Users model with maybe a column to flag an administrator (eg. is_admin or event a permissions level to make Administrators and Moderators)?

Rails 3.1
ActiveAdmin 0.3.3
Devise 1.4.9

解决方案

For a quick code block of how to do this using an existing "User" model with activeadmin, the answer is actually really easy. In the 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

And just use what Devise already has set up for authentication. The redirect_to is where you want to send users who ARE signed in and DO NOT have administrative privileges.

这篇关于合并ActiveAdmin用户与现有的用户模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆