DONT DEEPLY NEST ROUTES DOOOOOOOOOONT!!!! On Tue, Sep 7, 2010 at 3:31 PM, Marnen Laibow-Koser <[email protected]>wrote:
> Ed wrote: > > Trying to convert my app (and brain) to RESTful routes from the old > > style. What is the accepted approach to nesting a resource within 2 > > other resources? > > Well, REST only has to do with routing and external interface. It tells > you nothing about the implementation details of how to structure your > controllers, which seems to be your real question here. > > > > > Example: > > > > Models > > > > Person has_many :scores > > Contest has_many :scores > > Score belongs_to :person, :contest > > > > Routes > > > > resources :people do > > resources :scores > > end > > > > resources :competitions do > > resources :scores > > end > > > > I want to be able to list scores by person, or by competition. Either > > of the these two paths will request the :index action in the :scores > > controller: > > > > GET /people/person_id/scores > > GET /contests/contest_id/scores > > > > So what is the best way to structure scores/index to deliver the > > appropriate list? > > > > I could test for the presence of params[person_id] or > > params[contest_id], then execute and render accordingly within > > the :index action. But that seems somewhat inelegant. > > Does it? If you want to reuse the same controller action, it seems > entirely reasonable to test the data you're getting passed. > > > Is there a > > better way? Should I have two separate actions within the :score > > controller, and modify my route mapping somehow to request the > > appropriate action? > > You could do that, certainly. I think I'd use the former solution, > though. > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > [email protected] > > -- > 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 post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<rubyonrails-talk%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

