ActiveAdmin中有争议的closure_tree.如何创建层次视图



至少我想在索引表中实现一些缩进。像这样:

+Parent
+--Child
   +--Child of Child
+--Child

所以我创建了以下内容:

ActiveAdmin.register Section do
  config.filters = false
  index do
    column :name do |s|
      " #{ "――" * s.depth } #{s.name}"
    end
    default_actions
  end
  controller do
    def collection
      Section.some_method_to_get_things_in_right_order
    end
  end
end

需要some_method返回活动记录关系,但我没有成功。最后以这种方式结束了。

sortable_treeactiveadmin插件与闭包树配合使用效果很好。

https://github.com/zorab47/active_admin-sortable_tree

它创建了一个简单的层次结构和可排序的视图。

只需将以下内容放入树模型资源(app/admin/TreeModel):(假设Rails>4,用您的值替换<..>)

ActiveAdmin.register TreeModel do
config.filters = false # the default filters don't work unfortunately
permit_params <YOUR_TREE_MODEL_ATTRIBUTES>
sortable tree: true,
               sorting_attribute: :<YOUR_SORT_ATTRIBUTE>,
               parent_method: :parent,
               children_method: :children,
               roots_method: :roots
index :as => :sortable do
    label :name # item content
        actions
  end
end

最新更新