Nesting of a three-tier resource in ruby ββon rails
I have three levels of deep nesting of resources like parent, child, comment
Rails.application.routes.draw do
resources :parents do
resources :children do
resources :grand_children
end
end
end
In action, grand_children#new
it warns that "parent must exist" can anyone help me how to create grand_children nested three levels deep?
source to share
In your model GrandChildren
, you might have belongs_to :child, optional: true
, but I'm not sure what will resolve your routing error, since nesting the route requires the parent to exist.
Perhaps the solution is instead for your action grand_children#new
to ensure that the parent child
exists and the foreign key child_id
is passed when the record is created grand_child
.
source to share