rails祖先组表视图



例如,我有这样的活动记录。低于

[{id: 1, ancestry: nil, name: "Person 1"},
{id: 2, ancestry: nil, name: "Person 2"},
{id: 3, ancestry: nil, name: "Person 3"},
{id: 4, ancestry: 1, name: "Child 1"},
{id: 5, ancestry: 1, name: "Child 2"},
{id: 6, ancestry: 1, name: "Child 3"},
{id: 7, ancestry: 2, name: "Child 4"},
{id: 8, ancestry: 2, name: "Child 5"},
{id: 9, ancestry: 2, name: "Child 6"},
{id: 10, ancestry: 3, name: "Child 7"},
{id: 11, ancestry: 3, name: "Child 8"},
{id: 12, ancestry: 3, name: "Child 9"}]

我在家族模型中使用祖先

如何在我的HTML中实现这个表视图需要看起来像这个

Parent Name Child Name   Action
Person 1                edit-btn delete-btn
Child 1     edit-btn delete-btn
Child 2     edit-btn delete-btn
Child 3     edit-btn delete-btn
Person 2                edit-btn delete-btn
Child 4     edit-btn delete-btn
Child 5     edit-btn delete-btn
Child 6     edit-btn delete-btn
Person 3                edit-btn delete-btn
Child 7     edit-btn delete-btn
Child 8     edit-btn delete-btn
Child 9     edit-btn delete-btn

类似于:

<% Person.roots.each do |root| %>
< render the Person row >
<% root.children.each do |child| %>
< render the Child row >
<% end %>
<% end %>

我想你在这里使用的是祖先宝石。

相关内容

  • 没有找到相关文章

最新更新