具有AJAX的ActiveAdmin + CanCan + AASM事件切换器 [英] ActiveAdmin + CanCan + AASM event switcher with AJAX
问题描述
As an admin I have a specific role
I want to see and switch event for object
Depends on my role
灵感来自 activeadmin_addons 及其枚举集成我想通过允许不同的管理员用户根据模型中特定事件/状态的能力/角色来更改事件,来为AASM提供类似的功能。
Inspired by activeadmin_addons and its Enum Integration I want to make similar functionality for AASM by letting diffent admin users change events depending on their abilities/roles for specific events/statuses in model.
推荐答案
先决条件:
宝石:ActiveAdmin,
宝石 active_admin_role已安装并在当前版本下使用AdminUser模型_admin_user设置(或与您的应用类似)。
Gem: ActiveAdmin, Gem 'active_admin_role', both are installed and working AdminUser model with current_admin_user setup (or similar to your app).
经过Rails 5.1.3的测试。
Tested with Rails 5.1.3.
完成后并部署/运行服务器,您必须在admin中重新加载权限并为管理员角色或 super_admin角色以外的角色启用 event_update。
After you finish and deploy/run server you must "Reload" Permissions in admin and enable "event_update" for manager or other than "super_admin" roles.
较小的插件会需要做:
(除了下面的附件)
Smaller addons you'll need to do: (in addition to below attached files)
在AdminUser模型中添加:
In your AdminUser model add:
include CanCan::Ability
include ActiveAdminRole::CanCan::Ability
在您的table_for中(在此处渲染数据列):
In your table_for (is where you render columns of data):
column 'Our Status' do |auction|
render 'admin/auctions/event_change', auction: auction
end
在initializers / active_admin.rb中,或者在任何需要的地方
In initializers/active_admin.rb or whenever you want
ActiveAdmin::ResourceController.class_eval do
protected
def current_ability
# Match to your current admin user
@current_ability ||= Ability.new(current_admin_user)
end
end
还要确保您的配置:
config.authorization_adapter = ActiveAdmin::CanCanAdapter
config.authorization_adapter = ActiveAdmin::CanCanAdapter
config.cancan_ability_class = 'Ability'
如果我忘记了什么,请原谅我,如果您有任何疑问或问题,请告诉我!
Pardon me if I forgot something, let me know if you have any question or problem !
这篇关于具有AJAX的ActiveAdmin + CanCan + AASM事件切换器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!