Serafino Picozzi
2013-Oct-02 10:30 UTC
Avoid deeply nested routes for many related resources
Hi all, I''m having some headaches on how to setup my routes for a small app I''m developing. The app has to store the results of a game I''m doing with some friends. I have 4 models, defined as follows: Match: has_many :scores Team: has_many :players Player: has_many :scores ; belongs_to :team Score: belongs_to :player ; belongs_to :match These are currently my routes: resources :teams, shallow: true do resources :players do resources :scores, only: [:index] end end resources :matches This allows the administrator to manage teams, players, and view the scores associated with a singla player. I can also display a list of all matches. Simple enough. The problem now is that I need some players, the leaders of each team, to see and edit the results for their team for a specific match: once they select a match the list at /matches/, i need to show them a list of all the players of their team with their score (if present) for that specific match, and from there allow them to edit or insert a score for each player (one at a time). I''m really having troubles defining the routes for this, because there are several models involved in the creation of a new score but I want to avoid nesting resources too much. How would you define routes for a situation like this one? Consider that the team can be found from the logged user data, so, at least for that, there''s no need to pass the team id around. If you have any question please ask, I''m sorry if maybe it''s not too clear but english is not my native language. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6c1af5a1350fe487e98593b9529649e7%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.