如何为完整的独立模型使用多个Active Admin实例 [英] How to use multiple Active Admin instances for Complete Separate Models

查看:114
本文介绍了如何为完整的独立模型使用多个Active Admin实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个型号:




  • 用户

  • 供应商



,我想提供2个隔离的Active Admin界面。
他们都有设计路线:

  devise_for:users,ActiveAdmin :: Devise.config 
devise_for:供应商,ActiveAdmin :: Devise.config(我可以不知何故说ActiveAdmin2 :: Devise.config)

用户将有权访问产品,订单和供应商只能访问产品。



理想情况下,我希望在应用中拥有不同的文件夹,并呈现不同的数据。 >

user / order.rb

  ActiveAdmin。注册订单do 
过滤器:电子邮件
过滤器:created_at,:label => 订单创建日期
过滤器:order_created

supplier / order.rb

  ActiveAdmin.register订单执行
过滤器:电子邮件

有没有办法初始化2个ActiveAdmin类并并行运行?



任何其他

解决方案

您可以使用命名空间。

 
ActiveAdmin.register订单,命名空间::供应商
#将在/ supplier / orders
可用

ActiveAdmin.register Order,namespace::user do
#可在/ user / orders
end

您可以为 config / initializers / active_admin.rb



中的每个命名空间自定义身份验证例如: p>

 
config.default_namespace =:user

config.namespace:supplier do | supplier |
supplier.authentication_method =:authenticate_supplier_user!
supplier.current_user_method =:current_supplier_user
supplier.logout_link_path =:destroy_supplier_user_session_path
supplier.root_to ='orders#index'
end

config.namespace:用户做|用户|
user.authentication_method = false
user.current_user_method =:current_user
user.logout_link_path = false

更多信息: http://activeadmin.info/docs/1-general-configuration .html#命名空间


I have 2 models:

  • Users
  • Suppliers

and I want to provide 2 isolated Active Admin interfaces. They both have devise routes:

devise_for :users, ActiveAdmin::Devise.config
devise_for :suppliers,   ActiveAdmin::Devise.config (can I somehow say ActiveAdmin2::Devise.config)

User will have access to Products, Orders and Supplier will have access to products only.

Ideally, I want to have different Folders in the app and present different data.

user/order.rb

ActiveAdmin.register Order do
  filter :email
  filter :created_at  , :label => "Order Creation Date"
  filter :order_created

supplier/order.rb

ActiveAdmin.register Order do
  filter :email

Is there any way to initialize 2 ActiveAdmin Classes and run them in parallel?

Any other better way to make it work under the same website/app?

解决方案

You can use namespaces for this.

ActiveAdmin.register Order, namespace: :supplier do
  # will be available at /supplier/orders
end

ActiveAdmin.register Order, namespace: :user do
  # available at /user/orders
end

You can customize the authentication for each namespace in config/initializers/active_admin.rb

For example:

  config.default_namespace = :user

  config.namespace :supplier do |supplier|
    supplier.authentication_method = :authenticate_supplier_user!
    supplier.current_user_method = :current_supplier_user
    supplier.logout_link_path = :destroy_supplier_user_session_path
    supplier.root_to = 'orders#index'
  end

  config.namespace :user do |user|
    user.authentication_method = false
    user.current_user_method = :current_user
    user.logout_link_path = false

More info on: http://activeadmin.info/docs/1-general-configuration.html#namespaces

这篇关于如何为完整的独立模型使用多个Active Admin实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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