rails 查看 bootstrap nav-tabs

rails view with bootstrap nav-tabs

我有两个模型。 parent,以及 child。每个parent有很多children

#parent model
class Parent < ApplicationRecord
  has_many :children
end

#child model
class Child < ApplicationRecord
  belongs_to :parent
end

我想使用 bootstrap nav-tabs,每个选项卡应该只显示 parent 的 children。任何帮助。

  1. 当 id 在 parent table = children.parent.id 中时,首先要做 select
    • ParentController
@parent_children = Parent.select('DISTINCT name').joins(:children).where('id' = 'children.parent.id')
  • @parent_children return parent 的唯一名称有 children