Reputation: 47
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
Reputation:
parent
table = children.parent.id
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