【问题标题】:Displaing closure_tree in ActiveAdmin. How to create hierarhical view?在 Active Admin 中显示closure_tree。如何创建分层视图?
【发布时间】:2013-08-08 16:42:00
【问题描述】:

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

+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 返回活动记录关系,但我没有成功。最后以this hacky 方式结束。

【问题讨论】:

  • 您有什么高级解决方案吗?顺便说一句,您可以使用名为:hash_tree_scope 的方法执行普通哈希树
  • 不幸的是,没有。我将继续使用 gist 中公开的代码。如果有人在这里指出活动管理员中分层数据表示的任何解决方案,那就太好了。

标签: ruby-on-rails activerecord activeadmin acts-as-tree


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多