I am building a site for users where these can create a bunch of scaffolds and for each scaffold the user can create a bunch of tracks. Now, it should be possible for a user to share scaffolds with other users (this is were I am stuck). Same for tracks.
So the main resources are users, scaffolds and tracks and since I want to display an index for each of these I have chosen nested routes so in the routes.rb file I have:
resources :users do
resources :scaffolds do
I have the the following models and corresponding controllers and views:
In the models user has_many :scaffolds, scaffold has_many :tracks and belong_to :user and track belong_to :scaffold
For the sharing I have a scaffold_relationship and a track_relationship model both with sharing and shared attributes in which I can store user_id and scaffold_id/track_id. Thus I can use the has_many :scaffold_relationships, foreign_key: “shared_id” and has_many :sharing, through :scaffold_relationships. Same for the track_relationship.
However, I am unsure if this is the way to go. I think I want separate scaffold and track sharing pages, and maybe it is better with separate resources for the relationships? In any case I am stuck with planning the correct routes.