Rails Routing 3 Levels Deep

Brendan Feltrup-Exum
I'm a beginner in rails so be gentle. I am working on an app design myself just to learn and see what I can build. Since I am a novice I am basically creating a multiple crud instance for different models that are all connected. The problem I am having is understanding how view links would be properly written. I know routing deep is not suggested but I would like to see it work first and then start learning shallow routing. The problem is that when I do shallow routing I do not understand the code for links and it all falls apart. I have tried posting on StackOverflow but the answers I get do not offer any help or at least direct me to a better source of information. 

So to explain the design and my question. 
I have a Project Model that belongs to the account (but the user/account doesnt matter at the moment). I have another model called Scene Heading(this belongs to Project). I have another model called Properties that is all alone and it belongs to the account. Now I have a join table model of Scouted Locations that has some fields but its to connect the Property to the Scout Location. 

Models are as Follows:
class Project < ApplicationRecord
acts_as_tenant :account  
belongs_to :account  
has_many :scene_headings, dependent: :destroy
end

class SceneHeading < ApplicationRecord  
acts_as_tenant :account  
belongs_to :account  
belongs_to :project  
has_many :scouted_locations  
has_many :properties, through: :scouted_locations
end

class Property < ApplicationRecord  
acts_as_tenant :account  
belongs_to :account  
has_many :scouted_locations  
has_many :scene_headings, through: :scouted_locations
end

class ScoutedLocation < ApplicationRecord  
acts_as_tenant :account  
belongs_to :account  
belongs_to :project  
belongs_to :scene_headings  
belongs_to :properties
end

So I have gotten this far and  you can see the connection to each one and my Scouted location is my join table for Scene Headings and Properties but also will be its own view/model to connect the two in the app. I want to be able to add a new Property from the Scouted Location tab and it add it to the DB and connect to Scene Headings. Or be able to select a previously added Property and attach it to Scene Heading. I hope this makes sense. 

Now my problem is that I know how to nest 2 deep. I have Scene Headings working just fine minus the dynamic menu but I will learn that later. I cannot figure out how to work the links to connect with the controller for the Scouted Location controller. Any thoughts? I apologize in advance as I am a novice who has mostly learned by trying and watching youtube vides or following other peoples tutorials. 
Brendan Feltrup-Exum
Ok so after not finding any good tutorials on how to handle proper routing with views I spent many hours fiddling with this. I ended up cleaning up my routes by making them shallow since that was the "best method". Then spending several more hours getting all the views cleaned up with the proper rails routes. But I noticed there were issues on the child pages not grabbing the proper parent ID. This was mostly a problem on the destroy routing because the edit function does not pull the parent ID in when using shallow routing as it doesn't need it anymore to edit the DB record unless deleting. So I discovered I needed to pass the parent id into the destroy redirect to get the routing back to the index view. If anyone else needs help I don't mind explaining this. I do plan on making a git hub repo of a basic rails app to share this more. Out of all the sites I have watched, from railscasts to gorails and all the youtube links I have not found a great resource to share how to make shallow routes with all the tweaks to views and controllers. I am sure this is "common knowledge" for experienced coders but there is a massive disconnect in the world of open learning on how to go from basis CRUD functions to making a more in-depth application with interconnected resources and child functions. 
Notifications
You’re not receiving notifications from this thread.
© 2022 GoRails, LLC