Class: Ability
- Inherits:
-
Object
- Object
- Ability
- Includes:
- CanCan::Ability
- Defined in:
- app/models/ability.rb
Instance Method Summary collapse
-
#check_role(current_user) ⇒ Object
设置验证权限.
-
#initialize(user) ⇒ Ability
constructor
ability实例化,并设置权限.
-
#set_init ⇒ Object
初始化权限.
Constructor Details
#initialize(user) ⇒ Ability
ability实例化,并设置权限
作者: 汤建华最后更新时间: 2013-11-23
参数
-
当前用户
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/ability.rb', line 10 def initialize(user) set_init if user can :manage, "main_index".to_sym if user.role.code == "admin" can :manage, :all else check_role user end if user.freezed!=0 cannot :manage, :all set_init end end can :manage, :root_path end |
Instance Method Details
#check_role(current_user) ⇒ Object
设置验证权限
作者: 汤建华最后更新时间: 2013-11-23
参数
-
当前用户
43 44 45 46 47 48 49 50 51 |
# File 'app/models/ability.rb', line 43 def check_role(current_user) fuctions = current_user.role_fuctions fuctions.each do |f| f.routepaths.each do |routepath| path = routepath.controllerpath+"_"+routepath.actionpath can :manage, :"#{path}" end end end |
#set_init ⇒ Object
初始化权限
作者: 汤建华最后更新时间: 2013-11-23
30 31 32 33 34 35 |
# File 'app/models/ability.rb', line 30 def set_init can :manage, "main_new".to_sym can :manage, "main_create".to_sym can :manage, "main_logout".to_sym can :manage, "main_wince".to_sym end |