ActiveAdmin,navigation_menu 具有自定义订单
ActiveAdmin, navigation_menu with custom order
我正在使用 Runy On Rails 和 ActiveAdmin gem。在我的管理配置中,我有一个 AdminPage (Clients
),它不应该出现在通常的菜单中。它应该在一个相关 AdminPage (Company
) 的导航菜单中。这样,我就可以看到公司的客户了。
所以,在我的 app/admin/people.rb
中,我有:
navigation_menu :company
在这个菜单中,我还有其他元素,一切都很有魅力。现在,我想对这些项目应用自定义订单。但是当我使用 priority
(就像我在应用程序中的常用菜单项中使用的那样)时,我的模型失去了它的 navigation_menu
。
所以,我不能有自定义优先级的子菜单。
我可以修改 navigation_menu
上的 priority/order 吗?
我认为这确实是一个 ActiveAdmin 问题。
我设法使用下面描述的 add_to_menu 方法的猴子补丁解决了问题。
它不是最优雅的,但它在 AA 中解决问题的同时完成了工作。
假设您想要 2 个父菜单项 Clients
和 Product
,并且每个菜单项都有 2 个子项。所有这些管理页面都在 navigation_menu :company
范围内,例如:
Clients
-> 1. ClientAddresses
-> 2. ClientProfiles
Products
-> 1. ProductCategories
-> 2. ProductCosts
所以猴子补丁是这样的:
# Put this in app/admin/components/menu.rb
module ActiveAdmin
class Resource
module Menu
def add_to_menu(menu_collection)
add_parent_options if forced_parents.keys.include? resource_name.plural.to_sym
if include_in_menu?
@menu_item = menu_collection.add navigation_menu_name, menu_item_options
end
end
def add_parent_options
priority, parent = forced_parents[resource_name.plural.to_sym]
@menu_item_options[:priority] = priority
@menu_item_options[:parent] = I18n.t("active_admin.menus.#{parent}")
end
def forced_parents
@forced_parents ||=
{
client_addresses: [1, :clients],
client_profiles: [2, :clients],
product_categories: [1, :products],
product_costs: [2, :products],
}
end
end
end
祝你好运
我正在使用 Runy On Rails 和 ActiveAdmin gem。在我的管理配置中,我有一个 AdminPage (Clients
),它不应该出现在通常的菜单中。它应该在一个相关 AdminPage (Company
) 的导航菜单中。这样,我就可以看到公司的客户了。
所以,在我的 app/admin/people.rb
中,我有:
navigation_menu :company
在这个菜单中,我还有其他元素,一切都很有魅力。现在,我想对这些项目应用自定义订单。但是当我使用 priority
(就像我在应用程序中的常用菜单项中使用的那样)时,我的模型失去了它的 navigation_menu
。
所以,我不能有自定义优先级的子菜单。
我可以修改 navigation_menu
上的 priority/order 吗?
我认为这确实是一个 ActiveAdmin 问题。
我设法使用下面描述的 add_to_menu 方法的猴子补丁解决了问题。
它不是最优雅的,但它在 AA 中解决问题的同时完成了工作。
假设您想要 2 个父菜单项 Clients
和 Product
,并且每个菜单项都有 2 个子项。所有这些管理页面都在 navigation_menu :company
范围内,例如:
Clients
-> 1. ClientAddresses
-> 2. ClientProfiles
Products
-> 1. ProductCategories
-> 2. ProductCosts
所以猴子补丁是这样的:
# Put this in app/admin/components/menu.rb
module ActiveAdmin
class Resource
module Menu
def add_to_menu(menu_collection)
add_parent_options if forced_parents.keys.include? resource_name.plural.to_sym
if include_in_menu?
@menu_item = menu_collection.add navigation_menu_name, menu_item_options
end
end
def add_parent_options
priority, parent = forced_parents[resource_name.plural.to_sym]
@menu_item_options[:priority] = priority
@menu_item_options[:parent] = I18n.t("active_admin.menus.#{parent}")
end
def forced_parents
@forced_parents ||=
{
client_addresses: [1, :clients],
client_profiles: [2, :clients],
product_categories: [1, :products],
product_costs: [2, :products],
}
end
end
end
祝你好运