2

At minimal I want to achieve some indentation in index table. Like this:

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

So I create the following:

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

It's need to some_method return active record relation, but I haven't succeed. And ended up with this hacky way.

4

1 回答 1

3

sortable_tree activeadmin插件非常适合我使用闭包树。

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
于 2016-06-03T00:31:14.520 回答