ash moon
ash moon

Reputation: 47

rails view with bootstrap nav-tabs

I have two models. parent, and child. each parent has many children

#parent model
class Parent < ApplicationRecord
  has_many :children
end

#child model
class Child < ApplicationRecord
  belongs_to :parent
end

I want to use bootstrap nav-tabs, each tab should show parent's children only. any help.

Upvotes: 1

Views: 71

Answers (1)

user11544535
user11544535

Reputation:

  1. First thing do select when id in parent table = children.parent.id
    • in ParentController
@parent_children = Parent.select('DISTINCT name').joins(:children).where('id' = 'children.parent.id')
  • @parent_children return unique name of parent has children

Upvotes: 1

Related Questions