How to use multiple Active Admin instances for Complete Separate Models

最后都变了- 提交于 2019-12-03 13:33:15

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/12386535/how-to-use-multiple-active-admin-instances-for-complete-separate-models

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!